Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1512615

[PATCH] fork: Prevent premature task stack freeing

From Andy Lutomirski <luto@kernel.org>
Newsgroups linux.kernel
Subject [PATCH] fork: Prevent premature task stack freeing
Date 2016-10-31 16:20 +0100
Message-ID <symxs-47I-17@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


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.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 kernel/fork.c | 4 ++++
 1 file changed, 4 insertions(+)

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)
 
 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:
-- 
2.7.4

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] fork: Prevent premature task stack freeing Andy Lutomirski <luto@kernel.org> - 2016-10-31 16:20 +0100
  [tip:core/urgent] fork: Add task stack refcounting sanity check and  prevent premature task stack freeing tip-bot for Andy Lutomirski <tipbot@zytor.com> - 2016-11-01 08:20 +0100

csiph-web