[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <8a5ccf7097c36d2926bfb29309d9e8d18b22add6.1470345772.git.jpoimboe@redhat.com>
Date: Thu, 4 Aug 2016 17:22:38 -0500
From: Josh Poimboeuf <jpoimboe@...hat.com>
To: Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...nel.org>,
"H . Peter Anvin" <hpa@...or.com>
Cc: x86@...nel.org, linux-kernel@...r.kernel.org,
Andy Lutomirski <luto@...capital.net>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Steven Rostedt <rostedt@...dmis.org>,
Brian Gerst <brgerst@...il.com>,
Kees Cook <keescook@...omium.org>,
Peter Zijlstra <peterz@...radead.org>,
Frederic Weisbecker <fweisbec@...il.com>,
Byungchul Park <byungchul.park@....com>
Subject: [PATCH v2 42/44] x86/unwind: warn on kernel stack corruption
Detect situations in the unwinder where the frame pointer refers to a
bad address, and print an appropriate warning.
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@...hat.com>
---
arch/x86/kernel/unwind_frame.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c
index f60a089..d90c2c9 100644
--- a/arch/x86/kernel/unwind_frame.c
+++ b/arch/x86/kernel/unwind_frame.c
@@ -135,8 +135,13 @@ bool unwind_next_frame(struct unwind_state *state)
* encoded regs pointer is on the IRQ stack but the regs
* themselves are on the task stack.
*/
- if (!update_stack_state(state, regs, sizeof(*regs)))
+ if (!update_stack_state(state, regs, sizeof(*regs))) {
+ printk_deferred_once(KERN_WARNING "WARNING: kernel stack frame pointer at %p in %s:%d decodes to bad regs pointer %p\n",
+ state->bp, state->task->comm, state->task->pid,
+ regs);
+
return false;
+ }
/*
* The regs are now safe to access and are made available to
@@ -157,8 +162,23 @@ bool unwind_next_frame(struct unwind_state *state)
* Make sure the next frame is on a valid stack and can be accessed
* safely.
*/
- if (!update_stack_state(state, next_bp, FRAME_HEADER_SIZE))
+ if (!update_stack_state(state, next_bp, FRAME_HEADER_SIZE)) {
+ /*
+ * The next frame isn't on a valid stack, and we haven't
+ * reached the end, which means something went wrong: either a
+ * bad next stack pointer or a bad frame pointer.
+ */
+ if (state->regs)
+ printk_deferred_once(KERN_WARNING "WARNING: kernel stack regs->bp at %p in %s:%d points to bad address %p\n",
+ state->bp, state->task->comm,
+ state->task->pid, regs);
+ else
+ printk_deferred_once(KERN_WARNING "WARNING: kernel stack frame pointer at %p in %s:%d points to bad address %p\n",
+ state->bp, state->task->comm,
+ state->task->pid, next_bp);
+
return false;
+ }
/* move to the next frame */
state->bp = next_bp;
--
2.7.4
Powered by blists - more mailing lists