From: Andrei Vagin <avagin@gmail.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: David Howells <dhowells@redhat.com>,
linux-fsdevel@vger.kernel.org, cgroups@vger.kernel.org,
Li Zefan <lizefan@huawei.com>
Subject: Re: [PATCH vfs/for-next v2] cgroup: fix top cgroup refcnt leak
Date: Wed, 2 Jan 2019 11:37:38 -0800 [thread overview]
Message-ID: <20190102193737.GC15489@gmail.com> (raw)
In-Reply-To: <20190102022804.GH2217@ZenIV.linux.org.uk>
On Wed, Jan 02, 2019 at 02:28:04AM +0000, Al Viro wrote:
> On Fri, Dec 28, 2018 at 04:04:00PM -0800, Andrei Vagin wrote:
> > It looks like the c6b3d5bcd67c ("cgroup: fix top cgroup refcnt leak")
> > commit was reverted by mistake.
> >
> > $ mkdir /tmp/cgroup
> > $ mkdir /tmp/cgroup2
> > $ mount -t cgroup -o none,name=test test /tmp/cgroup
> > $ mount -t cgroup -o none,name=test test /tmp/cgroup2
> > $ umount /tmp/cgroup
> > $ umount /tmp/cgroup2
> > $ cat /proc/self/cgroup | grep test
> > 12:name=test:/
> >
> > You can see the test cgroup was not freed.
> >
> > Cc: Li Zefan <lizefan@huawei.com>
> > Fixes: aea3f2676c83 ("kernfs, sysfs, cgroup, intel_rdt: Support fs_context")
> > Signed-off-by: Andrei Vagin <avagin@gmail.com>
> > ---
> >
> > v2: clean up code and add the vfs/for-next tag
> >
> > kernel/cgroup/cgroup.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
> > index fb0717696895..f63974a3725f 100644
> > --- a/kernel/cgroup/cgroup.c
> > +++ b/kernel/cgroup/cgroup.c
> > @@ -2047,6 +2047,9 @@ int cgroup_do_get_tree(struct fs_context *fc)
> > ret = 0;
> > if (ctx->kfc.new_sb_created)
> > goto out_cgrp;
> > + else
> > + cgroup_put(&ctx->root->cgrp);
> > +
> > apply_cgroup_root_flags(ctx->flags);
> > return 0;
>
> That looks horrible, especially since out_cgrp is return ret;
> If anything, it should be
> if (!ctx->kfc.new_sb_created) {
> cgroup_put(&ctx->root->cgrp);
> apply_cgroup_root_flags(ctx->flags);
> }
> return 0;
>
> What I don't understand is why apply_cgroup_root_flags() is not
> called in "new superblock" case here. It used to, prior to that
> conversion...
It is a good question and I don't have an answer on it. I think David
can tell more about this.
>
> Another fishy place I see there is
> nsdentry = kernfs_node_dentry(cgrp->kn, fc->root->d_sb);
> if (IS_ERR(nsdentry))
> return PTR_ERR(nsdentry);
> dput(fc->root);
> fc->root = nsdentry;
> What happens if we get here with non-NULL fc->root (and we'd better,
> after successful from kernfs_get_tree() a bit earlier) and hit that
> failure exit? A leak?
Yes, here is a leak too. I fixed it and sent v3, but then I decided that
it would be good to test this error path and found one more problem:
[ 22.669696] ================================================
[ 22.670468] WARNING: lock held when returning to user space!
[ 22.671225] 4.20.0-rc1-00081-g01a72fa4bd0e-dirty #12 Not tainted
[ 22.672018] ------------------------------------------------
[ 22.672817] mount/1148 is leaving the kernel with locks still held!
[ 22.673660] 1 lock held by mount/1148:
[ 22.674165] #0: 00000000c07be72c (&fc->fs_type->s_umount_key#41){+.+.}, at: grab_super+0x29/0x90
deactivate_locked_super() has to be called on the error path. I sent v4 with
this fix. I'm sorry for the noise in the mailing list, I had to test this code
before sending v3;
> With apologies for being MIA for a week - it had been insane here...
Good to see you back in stride.
next prev parent reply other threads:[~2019-01-02 19:37 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-28 23:59 [PATCH] cgroup: fix top cgroup refcnt leak Andrei Vagin
2018-12-29 0:04 ` [PATCH vfs/for-next v2] " Andrei Vagin
2018-12-30 19:41 ` Andrei Vagin
2019-01-02 2:28 ` Al Viro
2019-01-02 18:14 ` [PATCH vfs/for-next v3] " Andrei Vagin
2019-01-02 19:37 ` Andrei Vagin [this message]
2019-01-02 19:37 ` [PATCH vfs/for-next v4] " Andrei Vagin
2019-01-02 20:02 ` Al Viro
2019-01-02 21:06 ` Andrei Vagin
2019-01-03 0:26 ` David Howells
2019-01-03 0:43 ` Andrei Vagin
2019-01-03 1:00 ` Andrei Vagin
2019-01-03 3:54 ` [PATCH vfs/for-next v6] " Andrei Vagin
2019-01-03 8:32 ` Al Viro
2019-01-03 17:34 ` Andrei Vagin
2019-01-03 21:54 ` David Howells
2019-01-02 22:26 ` [PATCH vfs/for-next v2] " David Howells
2019-01-02 23:06 ` Andrei Vagin
2019-01-02 23:31 ` Andrei Vagin
2019-01-03 0:33 ` David Howells
2019-01-03 13:41 ` David Howells
2019-01-03 13:42 ` David Howells
2019-01-03 15:27 ` David Howells
2019-01-03 15:44 ` David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190102193737.GC15489@gmail.com \
--to=avagin@gmail.com \
--cc=cgroups@vger.kernel.org \
--cc=dhowells@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).