projects
/
openwrt
/
staging
/
blogic.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
0c183d9
)
fork: Add task stack refcounting sanity check and prevent premature task stack freeing
author
Andy Lutomirski
<
[email protected]
>
Mon, 31 Oct 2016 15:11:43 +0000
(08:11 -0700)
committer
Ingo Molnar
<
[email protected]
>
Tue, 1 Nov 2016 06:39:17 +0000
(07:39 +0100)
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 <
[email protected]
>
Cc: Borislav Petkov <
[email protected]
>
Cc: Brian Gerst <
[email protected]
>
Cc: Denys Vlasenko <
[email protected]
>
Cc: H. Peter Anvin <
[email protected]
>
Cc: Josh Poimboeuf <
[email protected]
>
Cc: Linus Torvalds <
[email protected]
>
Cc: Oleg Nesterov <
[email protected]
>
Cc: Peter Zijlstra <
[email protected]
>
Cc: Thomas Gleixner <
[email protected]
>
Link:
http://lkml.kernel.org/r/f29119c783a9680a4b4656e751b6123917ace94b.1477926663.git.luto@kernel.org
Signed-off-by: Ingo Molnar <
[email protected]
>
kernel/fork.c
patch
|
blob
|
history
diff --git
a/kernel/fork.c
b/kernel/fork.c
index 623259fc794d034f7b4ab9144e2a61a7233381b6..997ac1d584f76b0e42551975bdae960e61c0807e 100644
(file)
--- 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
@@
bad_fork_cleanup_count:
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: