Commit c5ee5868 authored by Tejun Heo's avatar Tejun Heo Committed by Ben Hutchings

device_cgroup: fix RCU usage

commit 201e72ac upstream.

dev_cgroup->exceptions is protected with devcgroup_mutex for writes
and RCU for reads; however, RCU usage isn't correct.

* dev_exception_clean() doesn't use RCU variant of list_del() and
  kfree().  The function can race with may_access() and may_access()
  may end up dereferencing already freed memory.  Use list_del_rcu()
  and kfree_rcu() instead.

* may_access() may be called only with RCU read locked but doesn't use
  RCU safe traversal over ->exceptions.  Use list_for_each_entry_rcu().
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
Cc: Aristeu Rozanski <aris@redhat.com>
Cc: Li Zefan <lizefan@huawei.com>
[bwh: Backported to 3.2:
 - Adjust context
 - Exception list is called whitelist]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 3e1fab33
......@@ -202,8 +202,8 @@ static void devcgroup_destroy(struct cgroup_subsys *ss,
dev_cgroup = cgroup_to_devcgroup(cgroup);
list_for_each_entry_safe(wh, tmp, &dev_cgroup->whitelist, list) {
list_del(&wh->list);
kfree(wh);
list_del_rcu(&wh->list);
kfree_rcu(wh, rcu);
}
kfree(dev_cgroup);
}
......@@ -278,7 +278,7 @@ static int may_access_whitelist(struct dev_cgroup *c,
{
struct dev_whitelist_item *whitem;
list_for_each_entry(whitem, &c->whitelist, list) {
list_for_each_entry_rcu(whitem, &c->whitelist, list) {
if (whitem->type & DEV_ALL)
return 1;
if ((refwh->type & DEV_BLOCK) && !(whitem->type & DEV_BLOCK))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment