x86/unwind: Detect bad stack return address
authorJosh Poimboeuf <jpoimboe@redhat.com>
Wed, 26 Oct 2016 15:41:51 +0000 (10:41 -0500)
committerIngo Molnar <mingo@kernel.org>
Thu, 27 Oct 2016 06:32:38 +0000 (08:32 +0200)
If __kernel_text_address() doesn't recognize a return address on the
stack, it probably means that it's some generated code which
__kernel_text_address() doesn't know about yet.

Otherwise there's probably some stack corruption.

Either way, warn about it.

Use printk_deferred_once() because the unwinder can be called with the
console lock by lockdep via save_stack_trace().

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: 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: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/2d897898f324e275943b590d160b55e482bba65f.1477496147.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/kernel/unwind_frame.c

index 9be9a8f8c5dfeba9406b4a04cc50fc0f36fbae19..5639db619c03b53e545a61141804a1d975f2e3cf 100644 (file)
@@ -20,7 +20,15 @@ unsigned long unwind_get_return_address(struct unwind_state *state)
        addr = ftrace_graph_ret_addr(state->task, &state->graph_idx, *addr_p,
                                     addr_p);
 
-       return __kernel_text_address(addr) ? addr : 0;
+       if (!__kernel_text_address(addr)) {
+               printk_deferred_once(KERN_WARNING
+                       "WARNING: unrecognized kernel stack return address %p at %p in %s:%d\n",
+                       (void *)addr, addr_p, state->task->comm,
+                       state->task->pid);
+               return 0;
+       }
+
+       return addr;
 }
 EXPORT_SYMBOL_GPL(unwind_get_return_address);