Re: [PATCH] kthread: fix use-after-free if kthread fork fails
From: Oleg Nesterov
Date: Sat May 06 2017 - 15:51:51 EST
On 05/05, Vegard Nossum wrote:
>
> On 05/05/17 18:44, Oleg Nesterov wrote:
> >
> >Can't we just move both
> >
> > p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
> > /*
> > * Clear TID on mm_release()?
> > */
> > p->clear_child_tid = (clone_flags & CLONE_CHILD_CLEARTID) ? child_tidptr : NULL;
> >
> >lines here?
>
> clone_flags is not available in dup_task_struct(), but we could move
> those lines higher in copy_process().
Yes, yes, this is what I meant.
> The newly attached patch has been tested and seems to work, if you
> prefer it.
Yes, please, this loos a bit better simply because we do not need to set it twice.
And I agree this needs cleanups. Even if we forget about this particular problem
and the usage of set_child_tid, we should add copy_misc() which should absorb a
lot of chaotic initializations from copy_process() imo.
Oleg.