From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753844Ab2INN1t (ORCPT ); Fri, 14 Sep 2012 09:27:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59090 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751818Ab2INN1r (ORCPT ); Fri, 14 Sep 2012 09:27:47 -0400 Date: Fri, 14 Sep 2012 09:27:38 -0400 From: Aristeu Rozanski To: Jiri Slaby Cc: akpm@linux-foundation.org, jirislaby@gmail.com, linux-kernel@vger.kernel.org, Tejun Heo , lizefan@huawei.com Subject: Re: [PATCH] cgroup: fix invalid rcu dereference Message-ID: <20120914132738.GN19694@redhat.com> References: <5052F78A.7010007@suse.cz> <1347615612-11450-1-git-send-email-jslaby@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1347615612-11450-1-git-send-email-jslaby@suse.cz> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 14, 2012 at 11:40:12AM +0200, Jiri Slaby wrote: > Commit "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. ugh, missed that > > 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 > ------------------------------- > /home/latest/linux/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: [] > mnt_want_write+0x1f/0x50 > #1: (&sb->s_type->i_mutex_key#3/1){+.+.+.}, at: [] > 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 > [] ? ns_capable+0x44/0x80 > [] 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 > [] ? retint_restore_args+0xe/0xe > [] ? kthread_create_on_node+0x140/0x140 > [] ? gs_change+0xb/0xb > > Signed-off-by: Jiri Slaby > Cc: aris@redhat.com > Cc: Andrew Morton > Cc: Tejun Heo > Cc: lizefan@huawei.com > --- > > And this should fix it. > > security/device_cgroup.c | 15 +++++++-------- > 1 file changed, 7 insertions(+), 8 deletions(-) > > diff --git a/security/device_cgroup.c b/security/device_cgroup.c > index 8d21ded..2178886 100644 > --- a/security/device_cgroup.c > +++ b/security/device_cgroup.c > @@ -524,10 +524,10 @@ struct cgroup_subsys devices_subsys = { > * > * returns 0 on success, -EPERM case the operation is not permitted > */ > -static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup, > - short type, u32 major, u32 minor, > +static int __devcgroup_check_permission(short type, u32 major, u32 minor, > short access) > { > + struct dev_cgroup *dev_cgroup; > struct dev_exception_item ex; > int rc; > > @@ -538,6 +538,7 @@ static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup, > ex.access = access; > > rcu_read_lock(); > + dev_cgroup = task_devcgroup(current); > rc = may_access(dev_cgroup, &ex); > rcu_read_unlock(); > > @@ -549,7 +550,6 @@ static int __devcgroup_check_permission(struct dev_cgroup *dev_cgroup, > > int __devcgroup_inode_permission(struct inode *inode, int mask) > { > - struct dev_cgroup *dev_cgroup = task_devcgroup(current); > short type, access = 0; > > if (S_ISBLK(inode->i_mode)) > @@ -561,13 +561,12 @@ int __devcgroup_inode_permission(struct inode *inode, int mask) > if (mask & MAY_READ) > access |= ACC_READ; > > - return __devcgroup_check_permission(dev_cgroup, type, imajor(inode), > - iminor(inode), access); > + return __devcgroup_check_permission(type, imajor(inode), iminor(inode), > + access); > } > > int devcgroup_inode_mknod(int mode, dev_t dev) > { > - struct dev_cgroup *dev_cgroup = task_devcgroup(current); > short type; > > if (!S_ISBLK(mode) && !S_ISCHR(mode)) > @@ -578,7 +577,7 @@ int devcgroup_inode_mknod(int mode, dev_t dev) > else > type = DEV_CHAR; > > - return __devcgroup_check_permission(dev_cgroup, type, MAJOR(dev), > - MINOR(dev), ACC_MKNOD); > + return __devcgroup_check_permission(type, MAJOR(dev), MINOR(dev), > + ACC_MKNOD); > > } thanks Jiri Acked-by: Aristeu Rozanski -- Aristeu