Re: [syzbot] WARNING in kthread_is_per_cpu

From: Peter Zijlstra
Date: Tue Apr 20 2021 - 06:12:15 EST


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.