Re: [syzbot] WARNING in kthread_is_per_cpu

From: Valentin Schneider
Date: Tue Apr 20 2021 - 06:17:21 EST


On 20/04/21 12:11, Peter Zijlstra wrote:
> On Tue, Apr 20, 2021 at 10:43:43AM +0100, Valentin Schneider wrote:
>> On 20/04/21 10:51, Peter Zijlstra wrote:
>
>> > I think free_kthread_struct() is ok, because a task at that point in its
>> > lifetime cannot be also doing exec().
>> >
>>
>> What if it's one of those kthreads created by directly invoking
>> kernel_thread()? AFAICT right now it's only umh, and that one does execve()
>> so it ends up stripped of PF_KTHREAD. It could however go through an error
>> path, i.e. not call exec, and exit, giving us:
>>
>> put_task_struct(p)
>> `\
>> free_task(p)
>> `\
>> if (tsk->flags & PF_KTHREAD)
>> free_kthread_struct(tsk);
>> `\
>> to_kthread(p)
>
> I'm not following, at the point we hit free_task() it had better be dead
> and p->flags had better be stable. Either it will, or will not, have
> PF_KTHREAD.

Bah, don't mind me, for some reason I was obsessed by that umh thing of
having

(p->flags & PF_KTHREAD) && !p->set_child_tid

but that's not a problem there. Sorry about that.