diff options
author | Jiri Slaby <jslaby@suse.cz> | 2012-10-25 16:37:34 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-25 17:37:52 -0400 |
commit | 8c9506d16925f1b1314d93af383ca3134eb534d8 (patch) | |
tree | e14dbc5816b375463b8d37eda0f79bcd0ea96a3b /security | |
parent | ef5d437f71afdf4afdbab99213add99f4b1318fd (diff) |
cgroup: fix invalid rcu dereference
Commit ad676077a2ae ("device_cgroup: convert device_cgroup internally to
policy + exceptions") removed rcu locks which are needed in
task_devcgroup called in this chain:
devcgroup_inode_mknod OR __devcgroup_inode_permission ->
__devcgroup_inode_permission ->
task_devcgroup ->
task_subsys_state ->
task_subsys_state_check.
Change the code so that task_devcgroup is safely called with rcu read
lock held.
===============================
[ INFO: suspicious RCU usage. ]
3.6.0-rc5-next-20120913+ #42 Not tainted
-------------------------------
include/linux/cgroup.h:553 suspicious rcu_dereference_check() usage!
other info that might help us debug this:
rcu_scheduler_active = 1, debug_locks = 0
2 locks held by kdevtmpfs/23:
#0: (sb_writers){.+.+.+}, at: [<ffffffff8116873f>]
mnt_want_write+0x1f/0x50
#1: (&sb->s_type->i_mutex_key#3/1){+.+.+.}, at: [<ffffffff811558af>]
kern_path_create+0x7f/0x170
stack backtrace:
Pid: 23, comm: kdevtmpfs Not tainted 3.6.0-rc5-next-20120913+ #42
Call Trace:
lockdep_rcu_suspicious+0xfd/0x130
devcgroup_inode_mknod+0x19d/0x240
vfs_mknod+0x71/0xf0
handle_create.isra.2+0x72/0x200
devtmpfsd+0x114/0x140
? handle_create.isra.2+0x200/0x200
kthread+0xd6/0xe0
kernel_thread_helper+0x4/0x10
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Dave Jones <davej@redhat.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Li Zefan <lizefan@huawei.com>
Cc: James Morris <jmorris@namei.org>
Cc: Pavel Emelyanov <xemul@openvz.org>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'security')
-rw-r--r-- | security/device_cgroup.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/security/device_cgroup.c b/security/device_cgroup.c index 44dfc415a379..46d01fcc0d15 100644 --- a/security/device_cgroup.c +++ b/security/device_cgroup.c | |||
@@ -533,10 +533,10 @@ struct cgroup_subsys devices_subsys = { | |||
533 | * | 533 | * |
534 | * returns 0 on success, -EPERM case the operation is not permitted | 534 | * returns 0 on success, -EPERM case the operation is not permitted |
535 | */ | 535 | */ |
536 | static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup, | 536 | static int __devcgroup_check_permission(short type, u32 major, u32 minor, |
537 | short type, u32 major, u32 minor, | ||
538 | short access) | 537 | short access) |
539 | { | 538 | { |
539 | struct dev_cgroup *dev_cgroup; | ||
540 | struct dev_exception_item ex; | 540 | struct dev_exception_item ex; |
541 | int rc; | 541 | int rc; |
542 | 542 | ||
@@ -547,6 +547,7 @@ static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup, | |||
547 | ex.access = access; | 547 | ex.access = access; |
548 | 548 | ||
549 | rcu_read_lock(); | 549 | rcu_read_lock(); |
550 | dev_cgroup = task_devcgroup(current); | ||
550 | rc = may_access(dev_cgroup, &ex); | 551 | rc = may_access(dev_cgroup, &ex); |
551 | rcu_read_unlock(); | 552 | rcu_read_unlock(); |
552 | 553 | ||
@@ -558,7 +559,6 @@ static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup, | |||
558 | 559 | ||
559 | int __devcgroup_inode_permission(struct inode *inode, int mask) | 560 | int __devcgroup_inode_permission(struct inode *inode, int mask) |
560 | { | 561 | { |
561 | struct dev_cgroup *dev_cgroup = task_devcgroup(current); | ||
562 | short type, access = 0; | 562 | short type, access = 0; |
563 | 563 | ||
564 | if (S_ISBLK(inode->i_mode)) | 564 | if (S_ISBLK(inode->i_mode)) |
@@ -570,13 +570,12 @@ int __devcgroup_inode_permission(struct inode *inode, int mask) | |||
570 | if (mask & MAY_READ) | 570 | if (mask & MAY_READ) |
571 | access |= ACC_READ; | 571 | access |= ACC_READ; |
572 | 572 | ||
573 | return __devcgroup_check_permission(dev_cgroup, type, imajor(inode), | 573 | return __devcgroup_check_permission(type, imajor(inode), iminor(inode), |
574 | iminor(inode), access); | 574 | access); |
575 | } | 575 | } |
576 | 576 | ||
577 | int devcgroup_inode_mknod(int mode, dev_t dev) | 577 | int devcgroup_inode_mknod(int mode, dev_t dev) |
578 | { | 578 | { |
579 | struct dev_cgroup *dev_cgroup = task_devcgroup(current); | ||
580 | short type; | 579 | short type; |
581 | 580 | ||
582 | if (!S_ISBLK(mode) && !S_ISCHR(mode)) | 581 | if (!S_ISBLK(mode) && !S_ISCHR(mode)) |
@@ -587,7 +586,7 @@ int devcgroup_inode_mknod(int mode, dev_t dev) | |||
587 | else | 586 | else |
588 | type = DEV_CHAR; | 587 | type = DEV_CHAR; |
589 | 588 | ||
590 | return __devcgroup_check_permission(dev_cgroup, type, MAJOR(dev), | 589 | return __devcgroup_check_permission(type, MAJOR(dev), MINOR(dev), |
591 | MINOR(dev), ACC_MKNOD); | 590 | ACC_MKNOD); |
592 | 591 | ||
593 | } | 592 | } |