Commit 8c9506d1 authored by Jiri Slaby's avatar Jiri Slaby Committed by Linus Torvalds

cgroup: fix invalid rcu dereference

Commit ad676077 ("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: default avatarJiri 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: default avatarSerge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ef5d437f
...@@ -533,10 +533,10 @@ struct cgroup_subsys devices_subsys = { ...@@ -533,10 +533,10 @@ struct cgroup_subsys devices_subsys = {
* *
* returns 0 on success, -EPERM case the operation is not permitted * returns 0 on success, -EPERM case the operation is not permitted
*/ */
static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup, static int __devcgroup_check_permission(short type, u32 major, u32 minor,
short type, u32 major, u32 minor,
short access) short access)
{ {
struct dev_cgroup *dev_cgroup;
struct dev_exception_item ex; struct dev_exception_item ex;
int rc; int rc;
...@@ -547,6 +547,7 @@ static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup, ...@@ -547,6 +547,7 @@ static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup,
ex.access = access; ex.access = access;
rcu_read_lock(); rcu_read_lock();
dev_cgroup = task_devcgroup(current);
rc = may_access(dev_cgroup, &ex); rc = may_access(dev_cgroup, &ex);
rcu_read_unlock(); rcu_read_unlock();
...@@ -558,7 +559,6 @@ static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup, ...@@ -558,7 +559,6 @@ static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup,
int __devcgroup_inode_permission(struct inode *inode, int mask) int __devcgroup_inode_permission(struct inode *inode, int mask)
{ {
struct dev_cgroup *dev_cgroup = task_devcgroup(current);
short type, access = 0; short type, access = 0;
if (S_ISBLK(inode->i_mode)) if (S_ISBLK(inode->i_mode))
...@@ -570,13 +570,12 @@ int __devcgroup_inode_permission(struct inode *inode, int mask) ...@@ -570,13 +570,12 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
if (mask & MAY_READ) if (mask & MAY_READ)
access |= ACC_READ; access |= ACC_READ;
return __devcgroup_check_permission(dev_cgroup, type, imajor(inode), return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
iminor(inode), access); access);
} }
int devcgroup_inode_mknod(int mode, dev_t dev) int devcgroup_inode_mknod(int mode, dev_t dev)
{ {
struct dev_cgroup *dev_cgroup = task_devcgroup(current);
short type; short type;
if (!S_ISBLK(mode) && !S_ISCHR(mode)) if (!S_ISBLK(mode) && !S_ISCHR(mode))
...@@ -587,7 +586,7 @@ int devcgroup_inode_mknod(int mode, dev_t dev) ...@@ -587,7 +586,7 @@ int devcgroup_inode_mknod(int mode, dev_t dev)
else else
type = DEV_CHAR; type = DEV_CHAR;
return __devcgroup_check_permission(dev_cgroup, type, MAJOR(dev), return __devcgroup_check_permission(type, MAJOR(dev), MINOR(dev),
MINOR(dev), ACC_MKNOD); ACC_MKNOD);
} }
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