Re: [PATCH v4 5/6] clone3: allow spawning processes into cgroups

Christian Brauner
2020-01-20T21:39:11Z

On Mon, Jan 20, 2020 at 04:39:30PM +0100, Oleg Nesterov wrote:
> On 01/17, Christian Brauner wrote:
> >
> > +static int cgroup_css_set_fork(struct task_struct *parent,
> > + struct kernel_clone_args *kargs)
> ...
> > + kargs->cset = find_css_set(cset, dst_cgrp);
> > + if (!kargs->cset) {
> > + ret = -ENOMEM;
> > + goto err;
> > + }
> > +
> > + if (cgroup_is_dead(dst_cgrp)) {
> > + ret = -ENODEV;
> > + goto err;
> ^^^^^^^^
>
> this looks wrong... don't we need put_css_set(kargs->cset) before "goto err" ?

Yeah, but we should rather do:

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 4d36255ef25f..482055d1e64a 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -5994,6 +5994,8 @@ static int cgroup_css_set_fork(struct kernel_clone_args *kargs)
if (dst_cgrp)
cgroup_put(dst_cgrp);
put_css_set(cset);
+ if (kargs->cset)
+ put_css_set(kargs->cset);
return ret;
}

Christian