Skip to contentSkip to conversation

core fix for 4.9

GIT PULL Thomas Gleixner 1 participant 1 message Nov 5, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Linus,

please pull the latest core-urgent-for-linus git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git core-urgent-for-linus

Add a sanity check into release_task_stack() to catch problems with task stack references.

Thanks,

tglx

------------------>
Andy Lutomirski (1):
fork: Add task stack refcounting sanity check and prevent premature task stack freeing

 kernel/fork.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/fork.c +4 -0
index 623259fc794d..997ac1d584f7 100644
@@ -315,6 +315,9 @@ static void account_kernel_stack(struct task_struct *tsk, int account)
 
 static void release_task_stack(struct task_struct *tsk)
 {
+	if (WARN_ON(tsk->state != TASK_DEAD))
+		return;  /* Better to leak the stack than to free prematurely */
+
 	account_kernel_stack(tsk, -1);
 	arch_release_thread_stack(tsk->stack);
 	free_thread_stack(tsk);
@@ -1862,6 +1865,7 @@ static __latent_entropy struct task_struct *copy_process(
 	atomic_dec(&p->cred->user->processes);
 	exit_creds(p);
 bad_fork_free:
+	p->state = TASK_DEAD;
 	put_task_stack(p);
 	free_task(p);
 fork_out: