aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@kernel.org>2016-10-31 11:11:43 -0400
committerIngo Molnar <mingo@kernel.org>2016-11-01 02:39:17 -0400
commit405c0759712f57b680f66aee9c55cd06ad1cbdef (patch)
tree3a93cb428043131fd231b348dbe469be9dfadc30
parent0c183d92b20b5c84ca655b45ef57b3318b83eb9e (diff)
fork: Add task stack refcounting sanity check and prevent premature task stack freeing
If something goes wrong with task stack refcounting and a stack refcount hits zero too early, warn and leak it rather than potentially freeing it early (and silently). Signed-off-by: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/f29119c783a9680a4b4656e751b6123917ace94b.1477926663.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--kernel/fork.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 623259fc794d..997ac1d584f7 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -315,6 +315,9 @@ static void account_kernel_stack(struct task_struct *tsk, int account)
315 315
316static void release_task_stack(struct task_struct *tsk) 316static void release_task_stack(struct task_struct *tsk)
317{ 317{
318 if (WARN_ON(tsk->state != TASK_DEAD))
319 return; /* Better to leak the stack than to free prematurely */
320
318 account_kernel_stack(tsk, -1); 321 account_kernel_stack(tsk, -1);
319 arch_release_thread_stack(tsk->stack); 322 arch_release_thread_stack(tsk->stack);
320 free_thread_stack(tsk); 323 free_thread_stack(tsk);
@@ -1862,6 +1865,7 @@ bad_fork_cleanup_count:
1862 atomic_dec(&p->cred->user->processes); 1865 atomic_dec(&p->cred->user->processes);
1863 exit_creds(p); 1866 exit_creds(p);
1864bad_fork_free: 1867bad_fork_free:
1868 p->state = TASK_DEAD;
1865 put_task_stack(p); 1869 put_task_stack(p);
1866 free_task(p); 1870 free_task(p);
1867fork_out: 1871fork_out: