Skip to content

Commit 8c9506d

Browse files
Jiri Slabytorvalds
Jiri Slaby
authored andcommitted
cgroup: fix invalid rcu dereference
Commit ad67607 ("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+ hardkernel#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 hardkernel#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+ hardkernel#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 <[email protected]> Cc: Dave Jones <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Li Zefan <[email protected]> Cc: James Morris <[email protected]> Cc: Pavel Emelyanov <[email protected]> Acked-by: Serge Hallyn <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ef5d437 commit 8c9506d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Diff for: security/device_cgroup.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,10 @@ struct cgroup_subsys devices_subsys = {
533533
*
534534
* returns 0 on success, -EPERM case the operation is not permitted
535535
*/
536-
static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup,
537-
short type, u32 major, u32 minor,
536+
static int __devcgroup_check_permission(short type, u32 major, u32 minor,
538537
short access)
539538
{
539+
struct dev_cgroup *dev_cgroup;
540540
struct dev_exception_item ex;
541541
int rc;
542542

@@ -547,6 +547,7 @@ static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup,
547547
ex.access = access;
548548

549549
rcu_read_lock();
550+
dev_cgroup = task_devcgroup(current);
550551
rc = may_access(dev_cgroup, &ex);
551552
rcu_read_unlock();
552553

@@ -558,7 +559,6 @@ static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup,
558559

559560
int __devcgroup_inode_permission(struct inode *inode, int mask)
560561
{
561-
struct dev_cgroup *dev_cgroup = task_devcgroup(current);
562562
short type, access = 0;
563563

564564
if (S_ISBLK(inode->i_mode))
@@ -570,13 +570,12 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
570570
if (mask & MAY_READ)
571571
access |= ACC_READ;
572572

573-
return __devcgroup_check_permission(dev_cgroup, type, imajor(inode),
574-
iminor(inode), access);
573+
return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
574+
access);
575575
}
576576

577577
int devcgroup_inode_mknod(int mode, dev_t dev)
578578
{
579-
struct dev_cgroup *dev_cgroup = task_devcgroup(current);
580579
short type;
581580

582581
if (!S_ISBLK(mode) && !S_ISCHR(mode))
@@ -587,7 +586,7 @@ int devcgroup_inode_mknod(int mode, dev_t dev)
587586
else
588587
type = DEV_CHAR;
589588

590-
return __devcgroup_check_permission(dev_cgroup, type, MAJOR(dev),
591-
MINOR(dev), ACC_MKNOD);
589+
return __devcgroup_check_permission(type, MAJOR(dev), MINOR(dev),
590+
ACC_MKNOD);
592591

593592
}

0 commit comments

Comments
 (0)