Skip to content

Commit

Permalink
Merge branch 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/…
Browse files Browse the repository at this point in the history
…linux/kernel/git/tip/tip

Pull kthread fix from Thomas Gleixner:
 "A single fix which prevents a use after free when kthread fork fails"

* 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  kthread: Fix use-after-free if kthread fork fails
  • Loading branch information
Linus Torvalds committed May 27, 2017
2 parents 77d6465 + 4d6501d commit d024baa
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,18 @@ static __latent_entropy struct task_struct *copy_process(
if (!p)
goto fork_out;

/*
* This _must_ happen before we call free_task(), i.e. before we jump
* to any of the bad_fork_* labels. This is to avoid freeing
* p->set_child_tid which is (ab)used as a kthread's data pointer for
* kernel threads (PF_KTHREAD).
*/
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;

ftrace_graph_init_task(p);

rt_mutex_init_task(p);
Expand Down Expand Up @@ -1743,11 +1755,6 @@ static __latent_entropy struct task_struct *copy_process(
}
}

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;
#ifdef CONFIG_BLOCK
p->plug = NULL;
#endif
Expand Down

0 comments on commit d024baa

Please sign in to comment.