Re: cgroup.h:566 suspicious rcu_dereference_check() usage!

From: Paul E. McKenney
Date: Mon Oct 08 2012 - 15:52:20 EST


On Sat, Oct 06, 2012 at 09:16:07PM +0800, Fengguang Wu wrote:
> Hi Aristeu,
>
> I got the below warning in linus/master and linux-next, and it's
> bisected down to:

Cristian Rodríguez reported what looks like the same bug. Does the
patch below fix it?

Thanx, Paul

------------------------------------------------------------------------

device_cgroup: Restore rcu_read_lock() protection to devcgroup_inode_mknod()

Commit ad676077 (device_cgroup: convert device_cgroup internally to
policy + exceptions) restructured devcgroup_inode_mknod(), removing
rcu_read_lock() in the process. However, RCU read-side protection
is required by the call to task_devcgroup(), so this commit restores
the rcu_read_lock() and rcu_read_unlock().

Reported-by: Cristian Rodríguez <crrodriguez@xxxxxxxxxxxx>
Reported-by: Fengguang Wu <fengguang.wu@xxxxxxxxx>
Signed-off-by: Paul E. McKenney <paulmck@xxxxxxxxxxxxxxxxxx>

diff --git a/security/device_cgroup.c b/security/device_cgroup.c
index 44dfc41..c686110 100644
--- a/security/device_cgroup.c
+++ b/security/device_cgroup.c
@@ -576,9 +576,12 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)

int devcgroup_inode_mknod(int mode, dev_t dev)
{
- struct dev_cgroup *dev_cgroup = task_devcgroup(current);
+ struct dev_cgroup *dev_cgroup;
+ int ret;
short type;

+ rcu_read_lock();
+ dev_cgroup = task_devcgroup(current);
if (!S_ISBLK(mode) && !S_ISCHR(mode))
return 0;

@@ -587,7 +590,9 @@ int devcgroup_inode_mknod(int mode, dev_t dev)
else
type = DEV_CHAR;

- return __devcgroup_check_permission(dev_cgroup, type, MAJOR(dev),
+ ret = __devcgroup_check_permission(dev_cgroup, type, MAJOR(dev),
MINOR(dev), ACC_MKNOD);
+ rcu_read_unlock();
+ return ret;

}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/