Re: [PATCH] kernel/sched: Fix sched_fork() access an invalid sched_task_group

From: Tejun Heo
Date: Mon Aug 30 2021 - 13:32:13 EST


Hello,

On Mon, Aug 30, 2021 at 04:39:54PM +0200, Peter Zijlstra wrote:
> > When a new process is forked, cgroup_post_fork() associates it
> > with the cgroup of its parent. Therefore this commit move the
> > __set_task_cpu() and task_fork() that access some cgroup-related
> > fields(sched_task_group and cfs_rq) to sched_post_fork() and
> > call sched_post_fork() after cgroup_post_fork().

I think this would allow cgroup migrations to take place before
sched_post_fork() is run, which likely will break stuff. The right
thing to do likely is taking sched_task_group (and whatever other
fields) after cgroup_can_fork(), which fixates the cgroup memberships,
is run. For other controllers, operations like this would be performed
from cgroup_subsys->fork() callback but it's tricky for sched due to
autogroup.

> > Fixes: 8323f26ce342 ("sched: Fix race in task_group")
> > Signed-off-by: Zhang Qiao <zhangqiao22@xxxxxxxxxx>
>
> Hmm, I think you're right. Did something recently chagne in cgroup land
> to make this more visible? This code hasn't changed in like 9 years.

I can't think of any remotely recent change either. I guess ppl just
don't try to migrate the parent while fork is in progress.

Thanks.

--
tejun