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


Groups > linux.kernel > #1510122

[tip:x86/asm] x86/unwind: Detect bad stack return address

From tip-bot for Josh Poimboeuf <tipbot@zytor.com>
Newsgroups linux.kernel
Subject [tip:x86/asm] x86/unwind: Detect bad stack return address
Date 2016-10-27 09:40 +0200
Message-ID <swNs6-7eD-29@gated-at.bofh.it> (permalink)
References <swyCJ-5Mj-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Commit-ID:  b6959a362177053c1c90db6dc1af25b6bddd8548
Gitweb:     http://git.kernel.org/tip/b6959a362177053c1c90db6dc1af25b6bddd8548
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Wed, 26 Oct 2016 10:41:51 -0500
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 27 Oct 2016 08:32:38 +0200

x86/unwind: Detect bad stack return address

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 | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c
index 9be9a8f..5639db6 100644
--- a/arch/x86/kernel/unwind_frame.c
+++ b/arch/x86/kernel/unwind_frame.c
@@ -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);
 

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


Thread

[PATCH 0/4] x86/unwind: add some unwinder warnings Josh Poimboeuf <jpoimboe@redhat.com> - 2016-10-26 17:50 +0200
  [PATCH 4/4] x86/unwind: detect bad stack return address Josh Poimboeuf <jpoimboe@redhat.com> - 2016-10-26 17:50 +0200
    [tip:x86/asm] x86/unwind: Detect bad stack return address tip-bot for Josh Poimboeuf <tipbot@zytor.com> - 2016-10-27 09:40 +0200
  [PATCH 2/4] x86/unwind: ensure stack grows down Josh Poimboeuf <jpoimboe@redhat.com> - 2016-10-26 17:50 +0200
    Re: [PATCH 2/4] x86/unwind: ensure stack grows down Ingo Molnar <mingo@kernel.org> - 2016-10-27 08:40 +0200
      [PATCH v2] x86/unwind: ensure stack grows down Josh Poimboeuf <jpoimboe@redhat.com> - 2016-10-27 16:30 +0200
        [tip:x86/asm] x86/unwind: Ensure stack grows down tip-bot for Josh Poimboeuf <tipbot@zytor.com> - 2016-10-28 09:00 +0200
  [PATCH 3/4] x86/dumpstack: warn on stack recursion Josh Poimboeuf <jpoimboe@redhat.com> - 2016-10-26 17:50 +0200
    [tip:x86/asm] x86/dumpstack: Warn on stack recursion tip-bot for Josh Poimboeuf <tipbot@zytor.com> - 2016-10-27 09:50 +0200
  [PATCH 1/4] x86/unwind: warn on bad frame pointer Josh Poimboeuf <jpoimboe@redhat.com> - 2016-10-26 17:50 +0200
    [tip:x86/asm] x86/unwind: Warn on bad frame pointer tip-bot for Josh Poimboeuf <tipbot@zytor.com> - 2016-10-27 09:50 +0200

csiph-web