From: Waiman Long <longman@redhat.com>
To: Zou Cao <zoucaox@gmail.com>, linux-kernel@vger.kernel.org, tj@kernel.org
Cc: cgroups@vger.kernel.org, lizefan.x@bytedance.com,
hannes@cmpxchg.org, brauner@kernel.org,
Zou Cao <zoucao@kuaishou.com>
Subject: Re: [PATCH] cgroup: fixed the cset refcnt leak when fork() failed
Date: Mon, 5 Jun 2023 10:12:25 -0400 [thread overview]
Message-ID: <e0d1998f-c081-30e6-7646-cf6460c2d67c@redhat.com> (raw)
In-Reply-To: <20230605130444.1421-1-zoucao@kuaishou.com>
On 6/5/23 09:04, Zou Cao wrote:
> TeamID: B1486294
What is this?
>
> when fork, cset will be increased by commit "ef2c41cf38a7", the refcnt will
> be decrease by child exit, but when failed in fork(), this refcnt will
> be lost decrease in cgroup_cancel_fork as follow:
>
> copy_process
> |
> cgroup_can_fork // increase the css refcount
> ......
> spin_lock_irq(&css_set_lock);
> cset = task_css_setcurrent);
> get_css_set(cset);
> spin_unlock_irq&css_set_lock);
> ......
The code quoted above is actually in cgroup_css_set_fork(). You may want
to list it as well.
I believe the problem is in
if (!(kargs->flags & CLONE_INTO_CGROUP)) {
kargs->cset = cset;
return 0;
}
When CLONE_INTO_CGROUP isn't set, a reference to the current cset is taken.
> |
> goto cgroup_cancel_fork // if failed in copy_process
> |
> cgroup_cancel_fork // lost the decrease refcount if flag not CLONE_INTO_CGROUP
>
> Fixes: ef2c41cf38a7 ("clone3: allow spawning processes into cgroups")
> Signed-off-by: Zou Cao <zoucao@kuaishou.com>
> ---
> kernel/cgroup/cgroup.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
> index d18c2ef..5ecd706 100644
> --- a/kernel/cgroup/cgroup.c
> +++ b/kernel/cgroup/cgroup.c
> @@ -6284,6 +6284,11 @@ void cgroup_cancel_fork(struct task_struct *child,
> if (ss->cancel_fork)
> ss->cancel_fork(child, kargs->cset);
>
> + if (!(kargs->flags & CLONE_INTO_CGROUP) &&
> + kargs->cset) {
> + put_css_set(kargs->cset);
> + }
> +
I believe the out_revert error path of cgroup_can_fork() has a similar
issue. Perhaps you may want to put the put_css_set() call in
cgroup_css_set_put_fork().
> cgroup_css_set_put_fork(kargs);
> }
>
Cheers,
Longman
next prev parent reply other threads:[~2023-06-05 14:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-05 13:04 Zou Cao
2023-06-05 14:12 ` Waiman Long [this message]
2023-06-05 14:51 ` Waiman Long
2023-06-05 21:38 ` Tejun Heo
2023-06-06 2:32 ` Waiman Long
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=e0d1998f-c081-30e6-7646-cf6460c2d67c@redhat.com \
--to=longman@redhat.com \
--cc=brauner@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=tj@kernel.org \
--cc=zoucao@kuaishou.com \
--cc=zoucaox@gmail.com \
/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
all inboxes | Powered by JetHome®