diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-05-27 11:52:27 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-05-27 11:52:27 -0400 |
commit | d024baa58a4a7e5eb6058017771d15b9e47b56db (patch) | |
tree | 03e0a3338ecc033942c48acf51bac9138ef0dfd6 | |
parent | 77d64656950b299f5e7c70f1e3a0bdc991b51497 (diff) | |
parent | 4d6501dce079c1eb6bf0b1d8f528a5e81770109e (diff) |
Merge branch 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/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
-rw-r--r-- | kernel/fork.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index aa1076c5e4a9..e53770d2bf95 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -1577,6 +1577,18 @@ static __latent_entropy struct task_struct *copy_process( | |||
1577 | if (!p) | 1577 | if (!p) |
1578 | goto fork_out; | 1578 | goto fork_out; |
1579 | 1579 | ||
1580 | /* | ||
1581 | * This _must_ happen before we call free_task(), i.e. before we jump | ||
1582 | * to any of the bad_fork_* labels. This is to avoid freeing | ||
1583 | * p->set_child_tid which is (ab)used as a kthread's data pointer for | ||
1584 | * kernel threads (PF_KTHREAD). | ||
1585 | */ | ||
1586 | p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; | ||
1587 | /* | ||
1588 | * Clear TID on mm_release()? | ||
1589 | */ | ||
1590 | p->clear_child_tid = (clone_flags & CLONE_CHILD_CLEARTID) ? child_tidptr : NULL; | ||
1591 | |||
1580 | ftrace_graph_init_task(p); | 1592 | ftrace_graph_init_task(p); |
1581 | 1593 | ||
1582 | rt_mutex_init_task(p); | 1594 | rt_mutex_init_task(p); |
@@ -1743,11 +1755,6 @@ static __latent_entropy struct task_struct *copy_process( | |||
1743 | } | 1755 | } |
1744 | } | 1756 | } |
1745 | 1757 | ||
1746 | p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; | ||
1747 | /* | ||
1748 | * Clear TID on mm_release()? | ||
1749 | */ | ||
1750 | p->clear_child_tid = (clone_flags & CLONE_CHILD_CLEARTID) ? child_tidptr : NULL; | ||
1751 | #ifdef CONFIG_BLOCK | 1758 | #ifdef CONFIG_BLOCK |
1752 | p->plug = NULL; | 1759 | p->plug = NULL; |
1753 | #endif | 1760 | #endif |