stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Patch "cgroup: avoid attaching a cgroup root to two different superblocks" has been added to the 4.10-stable tree
@ 2017-04-18 10:39 gregkh
  2017-04-19  1:15 ` Zefan Li
  0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2017-04-18 10:39 UTC (permalink / raw)
  To: lizefan; +Cc: stable, stable-commits


This is a note to let you know that I've just added the patch titled

    cgroup: avoid attaching a cgroup root to two different superblocks

to the 4.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     cgroup-avoid-attaching-a-cgroup-root-to-two-different-superblocks.patch
and it can be found in the queue-4.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.


>From bfb0b80db5f9dca5ac0a5fd0edb765ee555e5a8e Mon Sep 17 00:00:00 2001
From: Zefan Li <lizefan@huawei.com>
Date: Fri, 7 Apr 2017 16:51:55 +0800
Subject: cgroup: avoid attaching a cgroup root to two different superblocks

From: Zefan Li <lizefan@huawei.com>

commit bfb0b80db5f9dca5ac0a5fd0edb765ee555e5a8e upstream.

Run this:

    touch file0
    for ((; ;))
    {
        mount -t cpuset xxx file0
    }

And this concurrently:

    touch file1
    for ((; ;))
    {
        mount -t cpuset xxx file1
    }

We'll trigger a warning like this:

 ------------[ cut here ]------------
 WARNING: CPU: 1 PID: 4675 at lib/percpu-refcount.c:317 percpu_ref_kill_and_confirm+0x92/0xb0
 percpu_ref_kill_and_confirm called more than once on css_release!
 CPU: 1 PID: 4675 Comm: mount Not tainted 4.11.0-rc5+ #5
 Hardware name: Bochs Bochs, BIOS Bochs 01/01/2007
 Call Trace:
  dump_stack+0x63/0x84
  __warn+0xd1/0xf0
  warn_slowpath_fmt+0x5f/0x80
  percpu_ref_kill_and_confirm+0x92/0xb0
  cgroup_kill_sb+0x95/0xb0
  deactivate_locked_super+0x43/0x70
  deactivate_super+0x46/0x60
 ...
 ---[ end trace a79f61c2a2633700 ]---

Here's a race:

  Thread A				Thread B

  cgroup1_mount()
    # alloc a new cgroup root
    cgroup_setup_root()
					cgroup1_mount()
					  # no sb yet, returns NULL
					  kernfs_pin_sb()

					  # but succeeds in getting the refcnt,
					  # so re-use cgroup root
					  percpu_ref_tryget_live()
    # alloc sb with cgroup root
    cgroup_do_mount()

  cgroup_kill_sb()
					  # alloc another sb with same root
					  cgroup_do_mount()

					cgroup_kill_sb()

We end up using the same cgroup root for two different superblocks,
so percpu_ref_kill() will be called twice on the same root when the
two superblocks are destroyed.

We should fix to make sure the superblock pinning is really successful.

Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Zefan Li <lizefan@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 kernel/cgroup.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -2195,7 +2195,7 @@ static struct dentry *cgroup_mount(struc
 		 * path is super cold.  Let's just sleep a bit and retry.
 		 */
 		pinned_sb = kernfs_pin_sb(root->kf_root, NULL);
-		if (IS_ERR(pinned_sb) ||
+		if (IS_ERR_OR_NULL(pinned_sb) ||
 		    !percpu_ref_tryget_live(&root->cgrp.self.refcnt)) {
 			mutex_unlock(&cgroup_mutex);
 			if (!IS_ERR_OR_NULL(pinned_sb))


Patches currently in stable-queue which might be from lizefan@huawei.com are

queue-4.10/cgroup-avoid-attaching-a-cgroup-root-to-two-different-superblocks.patch

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Patch "cgroup: avoid attaching a cgroup root to two different superblocks" has been added to the 4.10-stable tree
  2017-04-18 10:39 Patch "cgroup: avoid attaching a cgroup root to two different superblocks" has been added to the 4.10-stable tree gregkh
@ 2017-04-19  1:15 ` Zefan Li
  2017-04-19 11:31   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Zefan Li @ 2017-04-19  1:15 UTC (permalink / raw)
  To: gregkh; +Cc: stable

Hi Greg,

On 2017/4/18 18:39, gregkh@linuxfoundation.org wrote:
> 
> This is a note to let you know that I've just added the patch titled
> 
>     cgroup: avoid attaching a cgroup root to two different superblocks
> 
> to the 4.10-stable tree which can be found at:
>     http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
> 
> The filename of the patch is:
>      cgroup-avoid-attaching-a-cgroup-root-to-two-different-superblocks.patch
> and it can be found in the queue-4.10 subdirectory.
> 
> If you, or anyone else, feels it should not be added to the stable tree,
> please let <stable@vger.kernel.org> know about it.
> 

Please drop this patch, as it's broken. I've sent out a new fix, which has been
tested by Andrei. It will be merged in 4.12 as the bug isn't likely to happen
in real life.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Patch "cgroup: avoid attaching a cgroup root to two different superblocks" has been added to the 4.10-stable tree
  2017-04-19  1:15 ` Zefan Li
@ 2017-04-19 11:31   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2017-04-19 11:31 UTC (permalink / raw)
  To: Zefan Li; +Cc: stable

On Wed, Apr 19, 2017 at 09:15:50AM +0800, Zefan Li wrote:
> Hi Greg,
> 
> On 2017/4/18 18:39, gregkh@linuxfoundation.org wrote:
> > 
> > This is a note to let you know that I've just added the patch titled
> > 
> >     cgroup: avoid attaching a cgroup root to two different superblocks
> > 
> > to the 4.10-stable tree which can be found at:
> >     http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
> > 
> > The filename of the patch is:
> >      cgroup-avoid-attaching-a-cgroup-root-to-two-different-superblocks.patch
> > and it can be found in the queue-4.10 subdirectory.
> > 
> > If you, or anyone else, feels it should not be added to the stable tree,
> > please let <stable@vger.kernel.org> know about it.
> > 
> 
> Please drop this patch, as it's broken. I've sent out a new fix, which has been
> tested by Andrei. It will be merged in 4.12 as the bug isn't likely to happen
> in real life.

Ok, thanks, now dropped from all stable queues.

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-19 11:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-18 10:39 Patch "cgroup: avoid attaching a cgroup root to two different superblocks" has been added to the 4.10-stable tree gregkh
2017-04-19  1:15 ` Zefan Li
2017-04-19 11:31   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).