Skip to content

Commit 9a2e9da

Browse files
amlutoIngo Molnar
authored andcommitted
x86/dumpstack: Try harder to get a call trace on stack overflow
If we overflow the stack, print_context_stack() will abort. Detect this case and rewind back into the valid part of the stack so that we can trace it. Signed-off-by: Andy Lutomirski <luto@kernel.org> Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com> 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/ee1690eb2715ccc5dc187fde94effa4ca0ccbbcd.1468527351.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent d92fc69 commit 9a2e9da

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

arch/x86/kernel/dumpstack.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static inline int valid_stack_ptr(struct task_struct *task,
8787
else
8888
return 0;
8989
}
90-
return p > t && p < t + THREAD_SIZE - size;
90+
return p >= t && p < t + THREAD_SIZE - size;
9191
}
9292

9393
unsigned long
@@ -98,6 +98,14 @@ print_context_stack(struct task_struct *task,
9898
{
9999
struct stack_frame *frame = (struct stack_frame *)bp;
100100

101+
/*
102+
* If we overflowed the stack into a guard page, jump back to the
103+
* bottom of the usable stack.
104+
*/
105+
if ((unsigned long)task_stack_page(task) - (unsigned long)stack <
106+
PAGE_SIZE)
107+
stack = (unsigned long *)task_stack_page(task);
108+
101109
while (valid_stack_ptr(task, stack, sizeof(*stack), end)) {
102110
unsigned long addr;
103111

0 commit comments

Comments
 (0)