From: Andrei Vagin <avagin@gmail.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
David Howells <dhowells@redhat.com>
Cc: linux-fsdevel@vger.kernel.org, cgroups@vger.kernel.org,
Andrei Vagin <avagin@gmail.com>, Li Zefan <lizefan@huawei.com>
Subject: [PATCH vfs/for-next v6] cgroup: fix top cgroup refcnt leak
Date: Wed, 2 Jan 2019 19:54:26 -0800 [thread overview]
Message-ID: <20190103035426.23526-1-avagin@gmail.com> (raw)
In-Reply-To: <20190103010000.GA32003@gmail.com>
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
v3: fix a reference leak when kernfs_node_dentry fails
v4: call deactivate_locked_super() in a error case
v5: don't dereference fc->root after dput()
v6: rebase on today's vfs/for-next
kernel/cgroup/cgroup-v1.c | 2 +-
kernel/cgroup/cgroup.c | 25 ++++++++++++++++++-------
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c
index 4b189e821cad..de7d625ec077 100644
--- a/kernel/cgroup/cgroup-v1.c
+++ b/kernel/cgroup/cgroup-v1.c
@@ -1285,8 +1285,8 @@ int cgroup1_get_tree(struct fs_context *fc)
mutex_lock(&cgroup_mutex);
percpu_ref_reinit(&root->cgrp.self.refcnt);
mutex_unlock(&cgroup_mutex);
- cgroup_get(&root->cgrp);
}
+ cgroup_get(&root->cgrp);
/*
* If @pinned_sb, we're reusing an existing root and holding an
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index a19f0fec9d82..fe67b5e81f9a 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -2019,7 +2019,7 @@ int cgroup_do_get_tree(struct fs_context *fc)
ret = kernfs_get_tree(fc);
if (ret < 0)
- goto out_cgrp;
+ return ret;
/*
* In non-init cgroup namespace, instead of root cgroup's dentry,
@@ -2038,19 +2038,30 @@ int cgroup_do_get_tree(struct fs_context *fc)
mutex_unlock(&cgroup_mutex);
nsdentry = kernfs_node_dentry(cgrp->kn, fc->root->d_sb);
- if (IS_ERR(nsdentry))
- return PTR_ERR(nsdentry);
+ if (IS_ERR(nsdentry)) {
+ ret = PTR_ERR(nsdentry);
+ goto out_cgrp;
+ }
dput(fc->root);
fc->root = nsdentry;
}
ret = 0;
- if (ctx->kfc.new_sb_created)
- goto out_cgrp;
- apply_cgroup_root_flags(ctx->flags);
- return 0;
+ if (!ctx->kfc.new_sb_created)
+ apply_cgroup_root_flags(ctx->flags);
out_cgrp:
+ if (!ctx->kfc.new_sb_created)
+ cgroup_put(&ctx->root->cgrp);
+
+ if (unlikely(ret)) {
+ struct super_block *sb = fc->root->d_sb;
+
+ dput(fc->root);
+ deactivate_locked_super(sb);
+ fc->root = NULL;
+ }
+
return ret;
}
--
2.17.2
next prev parent reply other threads:[~2019-01-03 3:54 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 ` [PATCH vfs/for-next v2] " Andrei Vagin
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 ` Andrei Vagin [this message]
2019-01-03 8:32 ` [PATCH vfs/for-next v6] " 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=20190103035426.23526-1-avagin@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).