diff options
author | Tejun Heo <tj@kernel.org> | 2012-11-06 12:17:37 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2012-11-06 15:25:51 -0500 |
commit | 201e72acb2d3821e2de9ce6091e98859c316b29a (patch) | |
tree | 01e47038346474d659714151b8209673c11f330a /security | |
parent | 64e104771351d365e51e588a0e9a656ae6ed2f50 (diff) |
device_cgroup: fix RCU usage
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: Tejun Heo <tj@kernel.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Cc: stable@vger.kernel.org
Cc: Aristeu Rozanski <aris@redhat.com>
Cc: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'security')
-rw-r--r-- | security/device_cgroup.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/security/device_cgroup.c b/security/device_cgroup.c index 96d87eab1660..b08d20c66c2e 100644 --- a/security/device_cgroup.c +++ b/security/device_cgroup.c | |||
@@ -164,8 +164,8 @@ static void dev_exception_clean(struct dev_cgroup *dev_cgroup) | |||
164 | struct dev_exception_item *ex, *tmp; | 164 | struct dev_exception_item *ex, *tmp; |
165 | 165 | ||
166 | list_for_each_entry_safe(ex, tmp, &dev_cgroup->exceptions, list) { | 166 | list_for_each_entry_safe(ex, tmp, &dev_cgroup->exceptions, list) { |
167 | list_del(&ex->list); | 167 | list_del_rcu(&ex->list); |
168 | kfree(ex); | 168 | kfree_rcu(ex, rcu); |
169 | } | 169 | } |
170 | } | 170 | } |
171 | 171 | ||
@@ -298,7 +298,7 @@ static int may_access(struct dev_cgroup *dev_cgroup, | |||
298 | struct dev_exception_item *ex; | 298 | struct dev_exception_item *ex; |
299 | bool match = false; | 299 | bool match = false; |
300 | 300 | ||
301 | list_for_each_entry(ex, &dev_cgroup->exceptions, list) { | 301 | list_for_each_entry_rcu(ex, &dev_cgroup->exceptions, list) { |
302 | if ((refex->type & DEV_BLOCK) && !(ex->type & DEV_BLOCK)) | 302 | if ((refex->type & DEV_BLOCK) && !(ex->type & DEV_BLOCK)) |
303 | continue; | 303 | continue; |
304 | if ((refex->type & DEV_CHAR) && !(ex->type & DEV_CHAR)) | 304 | if ((refex->type & DEV_CHAR) && !(ex->type & DEV_CHAR)) |