Skip to content

Commit f12d11c

Browse files
thejhKAGA-KOKO
authored andcommitted
x86/entry/64: Wipe KASAN stack shadow before rewind_stack_do_exit()
Reset the KASAN shadow state of the task stack before rewinding RSP. Without this, a kernel oops will leave parts of the stack poisoned, and code running under do_exit() can trip over such poisoned regions and cause nonsensical false-positive KASAN reports about stack-out-of-bounds bugs. This does not wipe the exception stacks; if an oops happens on an exception stack, it might result in random KASAN false-positives from other tasks afterwards. This is probably relatively uninteresting, since if the kernel oopses on an exception stack, there are most likely bigger things to worry about. It'd be more interesting if vmapped stacks and KASAN were compatible, since then handle_stack_overflow() would oops from exception stack context. Fixes: 2deb4be ("x86/dumpstack: When OOPSing, rewind the stack before do_exit()") Signed-off-by: Jann Horn <jannh@google.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Alexander Potapenko <glider@google.com> Cc: Kees Cook <keescook@chromium.org> Cc: kasan-dev@googlegroups.com Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20180828184033.93712-1-jannh@google.com
1 parent 1f59a45 commit f12d11c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

arch/x86/kernel/dumpstack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/bug.h>
1818
#include <linux/nmi.h>
1919
#include <linux/sysfs.h>
20+
#include <linux/kasan.h>
2021

2122
#include <asm/cpu_entry_area.h>
2223
#include <asm/stacktrace.h>
@@ -346,7 +347,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
346347
* We're not going to return, but we might be on an IST stack or
347348
* have very little stack space left. Rewind the stack and kill
348349
* the task.
350+
* Before we rewind the stack, we have to tell KASAN that we're going to
351+
* reuse the task stack and that existing poisons are invalid.
349352
*/
353+
kasan_unpoison_task_stack(current);
350354
rewind_stack_do_exit(signr);
351355
}
352356
NOKPROBE_SYMBOL(oops_end);

0 commit comments

Comments
 (0)