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

From: Zhang Qiao
Date: Wed Sep 08 2021 - 07:32:17 EST




On 2021/9/8 1:01, Tejun Heo wrote:
> Hello,
>
> On Thu, Sep 02, 2021 at 03:42:15PM +0800, Zhang Qiao wrote:
>> I checked the code again.
>> I don't quite understand what you said, if the child be moved between
>> cgroup_post_fork() and sched_post_sched(), what problems might it cause?
>
> cgroup_post_fork() is where the child's creation is committed from cgroup's
> POV, so it'd be migrating cgroups before the initial creation is finished.
>>From glancing, looks like it'll break css_set task counts to begin with.
> This violates the basic assumptions and can cause critical failures in
> subtle ways. The would replace one subtle race with a possibly worse one.

Hello,

I will update this patch by following the steps below:
1)rename cgroup_subsys->fork() to cgroup_subsys->post_fork();
2)add cgroup_subsys->fork() and the cpu_cgroup_fork() callback like this:

void cpu_cgroup_fork(struct task_struct *task) {
....
p->sched_task_group = task_group(current);
__set_task_cpu(p, smp_processor_id());
if (p->sched_class->task_fork)
p->sched_class->task_fork(p);
....


3)call cgroup_subsys->fork() after cgroup_can_fork().

Do you have any suggestion?
thanks.

Zhang Qiao

>
> Thanks.
>