lkml.org 
[lkml]   [2016]   [Aug]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 44/44] x86/unwind: warn if stack grows up
Date
Add a sanity check to ensure the stack only grows down, and print a
warning if the check fails.

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>
---
arch/x86/kernel/unwind_frame.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c
index f943413..a29c342 100644
--- a/arch/x86/kernel/unwind_frame.c
+++ b/arch/x86/kernel/unwind_frame.c
@@ -107,6 +107,7 @@ bool unwind_next_frame(struct unwind_state *state)
{
struct pt_regs *regs;
unsigned long *next_bp;
+ enum stack_type prev_type = state->stack_info.type;

state->regs = NULL;

@@ -186,6 +187,15 @@ bool unwind_next_frame(struct unwind_state *state)
return false;
}

+ /* make sure the stack only unwinds up */
+ if (state->stack_info.type == prev_type && next_bp <= state->bp) {
+ printk_deferred_once(KERN_WARNING "WARNING: kernel stack frame pointer at %p in %s:%d points the wrong way (%p)\n",
+ state->bp, state->task->comm,
+ state->task->pid, next_bp);
+ state->stack_info.type = STACK_TYPE_UNKNOWN;
+ return false;
+ }
+
/* move to the next frame */
state->bp = next_bp;
return true;
--
2.7.4
\
 
 \ /
  Last update: 2016-08-05 01:01    [W:0.197 / U:1.508 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site