2019-05-19 12:08:55 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
#include <linux/sched.h>
|
2017-02-08 17:51:36 +00:00
|
|
|
#include <linux/sched/task.h>
|
2017-02-08 17:51:37 +00:00
|
|
|
#include <linux/sched/task_stack.h>
|
2017-04-12 18:47:12 +00:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <asm/sections.h>
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
#include <asm/ptrace.h>
|
|
|
|
#include <asm/bitops.h>
|
|
|
|
#include <asm/stacktrace.h>
|
|
|
|
#include <asm/unwind.h>
|
|
|
|
|
|
|
|
#define FRAME_HEADER_SIZE (sizeof(long) * 2)
|
|
|
|
|
2017-07-24 23:36:57 +00:00
|
|
|
unsigned long unwind_get_return_address(struct unwind_state *state)
|
|
|
|
{
|
|
|
|
if (unwind_done(state))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return __kernel_text_address(state->ip) ? state->ip : 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(unwind_get_return_address);
|
|
|
|
|
|
|
|
unsigned long *unwind_get_return_address_ptr(struct unwind_state *state)
|
|
|
|
{
|
|
|
|
if (unwind_done(state))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return state->regs ? &state->regs->ip : state->bp + 1;
|
|
|
|
}
|
2017-01-09 18:00:23 +00:00
|
|
|
|
2017-04-18 13:12:58 +00:00
|
|
|
static void unwind_dump(struct unwind_state *state)
|
2016-12-16 16:05:06 +00:00
|
|
|
{
|
|
|
|
static bool dumped_before = false;
|
|
|
|
bool prev_zero, zero = false;
|
2017-04-18 13:12:58 +00:00
|
|
|
unsigned long word, *sp;
|
2017-04-26 01:48:52 +00:00
|
|
|
struct stack_info stack_info = {0};
|
|
|
|
unsigned long visit_mask = 0;
|
2016-12-16 16:05:06 +00:00
|
|
|
|
|
|
|
if (dumped_before)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dumped_before = true;
|
|
|
|
|
2017-04-18 13:12:57 +00:00
|
|
|
printk_deferred("unwind stack type:%d next_sp:%p mask:0x%lx graph_idx:%d\n",
|
2016-12-16 16:05:06 +00:00
|
|
|
state->stack_info.type, state->stack_info.next_sp,
|
|
|
|
state->stack_mask, state->graph_idx);
|
|
|
|
|
2017-10-10 01:20:04 +00:00
|
|
|
for (sp = PTR_ALIGN(state->orig_sp, sizeof(long)); sp;
|
|
|
|
sp = PTR_ALIGN(stack_info.next_sp, sizeof(long))) {
|
2017-04-26 01:48:52 +00:00
|
|
|
if (get_stack_info(sp, state->task, &stack_info, &visit_mask))
|
|
|
|
break;
|
2016-12-16 16:05:06 +00:00
|
|
|
|
2017-04-26 01:48:52 +00:00
|
|
|
for (; sp < stack_info.end; sp++) {
|
2016-12-16 16:05:06 +00:00
|
|
|
|
2017-04-26 01:48:52 +00:00
|
|
|
word = READ_ONCE_NOCHECK(*sp);
|
|
|
|
|
|
|
|
prev_zero = zero;
|
|
|
|
zero = word == 0;
|
2016-12-16 16:05:06 +00:00
|
|
|
|
2017-04-26 01:48:52 +00:00
|
|
|
if (zero) {
|
|
|
|
if (!prev_zero)
|
|
|
|
printk_deferred("%p: %0*x ...\n",
|
|
|
|
sp, BITS_PER_LONG/4, 0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
printk_deferred("%p: %0*lx (%pB)\n",
|
|
|
|
sp, BITS_PER_LONG/4, word, (void *)word);
|
|
|
|
}
|
2016-12-16 16:05:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 18:47:12 +00:00
|
|
|
static bool in_entry_code(unsigned long ip)
|
|
|
|
{
|
|
|
|
char *addr = (char *)ip;
|
|
|
|
|
2020-06-10 06:37:01 +00:00
|
|
|
return addr >= __entry_text_start && addr < __entry_text_end;
|
2017-04-12 18:47:12 +00:00
|
|
|
}
|
|
|
|
|
2017-04-26 01:48:51 +00:00
|
|
|
static inline unsigned long *last_frame(struct unwind_state *state)
|
|
|
|
{
|
|
|
|
return (unsigned long *)task_pt_regs(state->task) - 2;
|
|
|
|
}
|
|
|
|
|
2017-05-23 15:37:30 +00:00
|
|
|
static bool is_last_frame(struct unwind_state *state)
|
|
|
|
{
|
|
|
|
return state->bp == last_frame(state);
|
|
|
|
}
|
|
|
|
|
2017-03-14 04:27:47 +00:00
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
#define GCC_REALIGN_WORDS 3
|
|
|
|
#else
|
|
|
|
#define GCC_REALIGN_WORDS 1
|
|
|
|
#endif
|
|
|
|
|
2017-04-26 01:48:51 +00:00
|
|
|
static inline unsigned long *last_aligned_frame(struct unwind_state *state)
|
|
|
|
{
|
|
|
|
return last_frame(state) - GCC_REALIGN_WORDS;
|
|
|
|
}
|
|
|
|
|
2017-05-23 15:37:30 +00:00
|
|
|
static bool is_last_aligned_frame(struct unwind_state *state)
|
2016-10-20 16:34:41 +00:00
|
|
|
{
|
2017-04-26 01:48:51 +00:00
|
|
|
unsigned long *last_bp = last_frame(state);
|
|
|
|
unsigned long *aligned_bp = last_aligned_frame(state);
|
2016-10-20 16:34:41 +00:00
|
|
|
|
2016-12-16 16:05:05 +00:00
|
|
|
/*
|
2017-05-23 15:37:30 +00:00
|
|
|
* GCC can occasionally decide to realign the stack pointer and change
|
|
|
|
* the offset of the stack frame in the prologue of a function called
|
|
|
|
* by head/entry code. Examples:
|
2017-03-14 04:27:47 +00:00
|
|
|
*
|
|
|
|
* <start_secondary>:
|
|
|
|
* push %edi
|
|
|
|
* lea 0x8(%esp),%edi
|
|
|
|
* and $0xfffffff8,%esp
|
|
|
|
* pushl -0x4(%edi)
|
|
|
|
* push %ebp
|
|
|
|
* mov %esp,%ebp
|
|
|
|
*
|
|
|
|
* <x86_64_start_kernel>:
|
|
|
|
* lea 0x8(%rsp),%r10
|
|
|
|
* and $0xfffffffffffffff0,%rsp
|
|
|
|
* pushq -0x8(%r10)
|
|
|
|
* push %rbp
|
|
|
|
* mov %rsp,%rbp
|
|
|
|
*
|
2017-05-23 15:37:30 +00:00
|
|
|
* After aligning the stack, it pushes a duplicate copy of the return
|
|
|
|
* address before pushing the frame pointer.
|
|
|
|
*/
|
|
|
|
return (state->bp == aligned_bp && *(aligned_bp + 1) == *(last_bp + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_last_ftrace_frame(struct unwind_state *state)
|
|
|
|
{
|
|
|
|
unsigned long *last_bp = last_frame(state);
|
|
|
|
unsigned long *last_ftrace_bp = last_bp - 3;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When unwinding from an ftrace handler of a function called by entry
|
|
|
|
* code, the stack layout of the last frame is:
|
|
|
|
*
|
|
|
|
* bp
|
|
|
|
* parent ret addr
|
|
|
|
* bp
|
|
|
|
* function ret addr
|
|
|
|
* parent ret addr
|
|
|
|
* pt_regs
|
|
|
|
* -----------------
|
2016-12-16 16:05:05 +00:00
|
|
|
*/
|
2017-05-23 15:37:30 +00:00
|
|
|
return (state->bp == last_ftrace_bp &&
|
|
|
|
*state->bp == *(state->bp + 2) &&
|
|
|
|
*(state->bp + 1) == *(state->bp + 4));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_last_task_frame(struct unwind_state *state)
|
|
|
|
{
|
|
|
|
return is_last_frame(state) || is_last_aligned_frame(state) ||
|
|
|
|
is_last_ftrace_frame(state);
|
2016-10-20 16:34:41 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 16:34:40 +00:00
|
|
|
/*
|
|
|
|
* This determines if the frame pointer actually contains an encoded pointer to
|
|
|
|
* pt_regs on the stack. See ENCODE_FRAME_POINTER.
|
|
|
|
*/
|
x86/unwind: Use MSB for frame pointer encoding on 32-bit
On x86-32, Tetsuo Handa and Fengguang Wu reported unwinder warnings
like:
WARNING: kernel stack regs at f60bb9c8 in swapper:1 has bad 'bp' value 0ba00000
And also there were some stack dumps with a bunch of unreliable '?'
symbols after an apic_timer_interrupt symbol, meaning the unwinder got
confused when it tried to read the regs.
The cause of those issues is that, with GCC 4.8 (and possibly older),
there are cases where GCC misaligns the stack pointer in a leaf function
for no apparent reason:
c124a388 <acpi_rs_move_data>:
c124a388: 55 push %ebp
c124a389: 89 e5 mov %esp,%ebp
c124a38b: 57 push %edi
c124a38c: 56 push %esi
c124a38d: 89 d6 mov %edx,%esi
c124a38f: 53 push %ebx
c124a390: 31 db xor %ebx,%ebx
c124a392: 83 ec 03 sub $0x3,%esp
...
c124a3e3: 83 c4 03 add $0x3,%esp
c124a3e6: 5b pop %ebx
c124a3e7: 5e pop %esi
c124a3e8: 5f pop %edi
c124a3e9: 5d pop %ebp
c124a3ea: c3 ret
If an interrupt occurs in such a function, the regs on the stack will be
unaligned, which breaks the frame pointer encoding assumption. So on
32-bit, use the MSB instead of the LSB to encode the regs.
This isn't an issue on 64-bit, because interrupts align the stack before
writing to it.
Reported-and-tested-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reported-and-tested-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Byungchul Park <byungchul.park@lge.com>
Cc: LKP <lkp@01.org>
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/279a26996a482ca716605c7dbc7f2db9d8d91e81.1507597785.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-10-10 01:20:03 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
2016-10-20 16:34:40 +00:00
|
|
|
static struct pt_regs *decode_frame_pointer(unsigned long *bp)
|
|
|
|
{
|
|
|
|
unsigned long regs = (unsigned long)bp;
|
|
|
|
|
|
|
|
if (!(regs & 0x1))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (struct pt_regs *)(regs & ~0x1);
|
|
|
|
}
|
x86/unwind: Use MSB for frame pointer encoding on 32-bit
On x86-32, Tetsuo Handa and Fengguang Wu reported unwinder warnings
like:
WARNING: kernel stack regs at f60bb9c8 in swapper:1 has bad 'bp' value 0ba00000
And also there were some stack dumps with a bunch of unreliable '?'
symbols after an apic_timer_interrupt symbol, meaning the unwinder got
confused when it tried to read the regs.
The cause of those issues is that, with GCC 4.8 (and possibly older),
there are cases where GCC misaligns the stack pointer in a leaf function
for no apparent reason:
c124a388 <acpi_rs_move_data>:
c124a388: 55 push %ebp
c124a389: 89 e5 mov %esp,%ebp
c124a38b: 57 push %edi
c124a38c: 56 push %esi
c124a38d: 89 d6 mov %edx,%esi
c124a38f: 53 push %ebx
c124a390: 31 db xor %ebx,%ebx
c124a392: 83 ec 03 sub $0x3,%esp
...
c124a3e3: 83 c4 03 add $0x3,%esp
c124a3e6: 5b pop %ebx
c124a3e7: 5e pop %esi
c124a3e8: 5f pop %edi
c124a3e9: 5d pop %ebp
c124a3ea: c3 ret
If an interrupt occurs in such a function, the regs on the stack will be
unaligned, which breaks the frame pointer encoding assumption. So on
32-bit, use the MSB instead of the LSB to encode the regs.
This isn't an issue on 64-bit, because interrupts align the stack before
writing to it.
Reported-and-tested-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reported-and-tested-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Byungchul Park <byungchul.park@lge.com>
Cc: LKP <lkp@01.org>
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/279a26996a482ca716605c7dbc7f2db9d8d91e81.1507597785.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-10-10 01:20:03 +00:00
|
|
|
#else
|
|
|
|
static struct pt_regs *decode_frame_pointer(unsigned long *bp)
|
|
|
|
{
|
|
|
|
unsigned long regs = (unsigned long)bp;
|
|
|
|
|
|
|
|
if (regs & 0x80000000)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (struct pt_regs *)(regs | 0x80000000);
|
|
|
|
}
|
|
|
|
#endif
|
2016-10-20 16:34:40 +00:00
|
|
|
|
2017-04-12 18:47:10 +00:00
|
|
|
static bool update_stack_state(struct unwind_state *state,
|
|
|
|
unsigned long *next_bp)
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
{
|
|
|
|
struct stack_info *info = &state->stack_info;
|
2017-04-12 18:47:10 +00:00
|
|
|
enum stack_type prev_type = info->type;
|
|
|
|
struct pt_regs *regs;
|
2017-04-12 18:47:11 +00:00
|
|
|
unsigned long *frame, *prev_frame_end, *addr_p, addr;
|
2017-04-12 18:47:10 +00:00
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (state->regs)
|
2019-05-07 21:25:54 +00:00
|
|
|
prev_frame_end = (void *)state->regs + sizeof(*state->regs);
|
2017-04-12 18:47:10 +00:00
|
|
|
else
|
|
|
|
prev_frame_end = (void *)state->bp + FRAME_HEADER_SIZE;
|
|
|
|
|
|
|
|
/* Is the next frame pointer an encoded pointer to pt_regs? */
|
|
|
|
regs = decode_frame_pointer(next_bp);
|
|
|
|
if (regs) {
|
|
|
|
frame = (unsigned long *)regs;
|
2019-05-07 21:25:54 +00:00
|
|
|
len = sizeof(*regs);
|
2017-04-12 18:47:12 +00:00
|
|
|
state->got_irq = true;
|
2017-04-12 18:47:10 +00:00
|
|
|
} else {
|
|
|
|
frame = next_bp;
|
|
|
|
len = FRAME_HEADER_SIZE;
|
|
|
|
}
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
|
|
|
|
/*
|
2017-04-12 18:47:10 +00:00
|
|
|
* If the next bp isn't on the current stack, switch to the next one.
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
*
|
|
|
|
* We may have to traverse multiple stacks to deal with the possibility
|
2017-04-12 18:47:10 +00:00
|
|
|
* that info->next_sp could point to an empty stack and the next bp
|
|
|
|
* could be on a subsequent stack.
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
*/
|
2017-04-12 18:47:10 +00:00
|
|
|
while (!on_stack(info, frame, len))
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
if (get_stack_info(info->next_sp, state->task, info,
|
|
|
|
&state->stack_mask))
|
|
|
|
return false;
|
|
|
|
|
2017-04-12 18:47:10 +00:00
|
|
|
/* Make sure it only unwinds up and doesn't overlap the prev frame: */
|
|
|
|
if (state->orig_sp && state->stack_info.type == prev_type &&
|
|
|
|
frame < prev_frame_end)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Move state to the next frame: */
|
|
|
|
if (regs) {
|
|
|
|
state->regs = regs;
|
|
|
|
state->bp = NULL;
|
|
|
|
} else {
|
|
|
|
state->bp = next_bp;
|
|
|
|
state->regs = NULL;
|
|
|
|
}
|
|
|
|
|
2017-04-12 18:47:11 +00:00
|
|
|
/* Save the return address: */
|
|
|
|
if (state->regs && user_mode(state->regs))
|
|
|
|
state->ip = 0;
|
|
|
|
else {
|
|
|
|
addr_p = unwind_get_return_address_ptr(state);
|
|
|
|
addr = READ_ONCE_TASK_STACK(state->task, *addr_p);
|
2021-09-14 14:42:31 +00:00
|
|
|
state->ip = unwind_recover_ret_addr(state, addr, addr_p);
|
2017-04-12 18:47:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 18:47:10 +00:00
|
|
|
/* Save the original stack pointer for unwind_dump(): */
|
2017-04-26 01:48:52 +00:00
|
|
|
if (!state->orig_sp)
|
2017-04-12 18:47:10 +00:00
|
|
|
state->orig_sp = frame;
|
2016-12-16 16:05:06 +00:00
|
|
|
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool unwind_next_frame(struct unwind_state *state)
|
|
|
|
{
|
2016-10-20 16:34:40 +00:00
|
|
|
struct pt_regs *regs;
|
2017-04-12 18:47:10 +00:00
|
|
|
unsigned long *next_bp;
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
|
|
|
|
if (unwind_done(state))
|
|
|
|
return false;
|
|
|
|
|
2017-04-12 18:47:10 +00:00
|
|
|
/* Have we reached the end? */
|
2016-10-20 16:34:40 +00:00
|
|
|
if (state->regs && user_mode(state->regs))
|
|
|
|
goto the_end;
|
|
|
|
|
2016-10-20 16:34:41 +00:00
|
|
|
if (is_last_task_frame(state)) {
|
|
|
|
regs = task_pt_regs(state->task);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kthreads (other than the boot CPU's idle thread) have some
|
|
|
|
* partial regs at the end of their stack which were placed
|
2020-06-11 09:04:15 +00:00
|
|
|
* there by copy_thread(). But the regs don't have any
|
2016-10-20 16:34:41 +00:00
|
|
|
* useful information, so we can skip them.
|
|
|
|
*
|
|
|
|
* This user_mode() check is slightly broader than a PF_KTHREAD
|
|
|
|
* check because it also catches the awkward situation where a
|
|
|
|
* newly forked kthread transitions into a user task by calling
|
2020-07-13 17:06:48 +00:00
|
|
|
* kernel_execve(), which eventually clears PF_KTHREAD.
|
2016-10-20 16:34:41 +00:00
|
|
|
*/
|
|
|
|
if (!user_mode(regs))
|
|
|
|
goto the_end;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We're almost at the end, but not quite: there's still the
|
|
|
|
* syscall regs frame. Entry code doesn't encode the regs
|
|
|
|
* pointer for syscalls, so we have to set it manually.
|
|
|
|
*/
|
|
|
|
state->regs = regs;
|
|
|
|
state->bp = NULL;
|
2017-04-12 18:47:11 +00:00
|
|
|
state->ip = 0;
|
2016-10-20 16:34:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-12 18:47:10 +00:00
|
|
|
/* Get the next frame pointer: */
|
2019-03-01 03:12:00 +00:00
|
|
|
if (state->next_bp) {
|
|
|
|
next_bp = state->next_bp;
|
|
|
|
state->next_bp = NULL;
|
|
|
|
} else if (state->regs) {
|
2016-10-20 16:34:40 +00:00
|
|
|
next_bp = (unsigned long *)state->regs->bp;
|
2019-03-01 03:12:00 +00:00
|
|
|
} else {
|
2017-04-12 18:47:10 +00:00
|
|
|
next_bp = (unsigned long *)READ_ONCE_TASK_STACK(state->task, *state->bp);
|
2019-03-01 03:12:00 +00:00
|
|
|
}
|
2016-10-20 16:34:40 +00:00
|
|
|
|
2017-04-12 18:47:10 +00:00
|
|
|
/* Move to the next frame if it's safe: */
|
2017-04-12 18:47:12 +00:00
|
|
|
if (!update_stack_state(state, next_bp))
|
2016-10-26 15:41:48 +00:00
|
|
|
goto bad_address;
|
|
|
|
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
return true;
|
2016-10-20 16:34:40 +00:00
|
|
|
|
2016-10-26 15:41:48 +00:00
|
|
|
bad_address:
|
2017-02-14 01:42:28 +00:00
|
|
|
state->error = true;
|
|
|
|
|
2017-01-09 18:00:22 +00:00
|
|
|
/*
|
|
|
|
* When unwinding a non-current task, the task might actually be
|
|
|
|
* running on another CPU, in which case it could be modifying its
|
|
|
|
* stack while we're reading it. This is generally not a problem and
|
|
|
|
* can be ignored as long as the caller understands that unwinding
|
|
|
|
* another task will not always succeed.
|
|
|
|
*/
|
|
|
|
if (state->task != current)
|
|
|
|
goto the_end;
|
|
|
|
|
2017-04-12 18:47:12 +00:00
|
|
|
/*
|
|
|
|
* Don't warn if the unwinder got lost due to an interrupt in entry
|
2017-04-26 01:48:51 +00:00
|
|
|
* code or in the C handler before the first frame pointer got set up:
|
2017-04-12 18:47:12 +00:00
|
|
|
*/
|
|
|
|
if (state->got_irq && in_entry_code(state->ip))
|
|
|
|
goto the_end;
|
2017-04-26 01:48:51 +00:00
|
|
|
if (state->regs &&
|
|
|
|
state->regs->sp >= (unsigned long)last_aligned_frame(state) &&
|
|
|
|
state->regs->sp < (unsigned long)task_pt_regs(state->task))
|
|
|
|
goto the_end;
|
2017-04-12 18:47:12 +00:00
|
|
|
|
2017-10-10 01:20:05 +00:00
|
|
|
/*
|
|
|
|
* There are some known frame pointer issues on 32-bit. Disable
|
|
|
|
* unwinder warnings on 32-bit until it gets objtool support.
|
|
|
|
*/
|
|
|
|
if (IS_ENABLED(CONFIG_X86_32))
|
|
|
|
goto the_end;
|
|
|
|
|
2020-04-25 10:03:06 +00:00
|
|
|
if (state->task != current)
|
|
|
|
goto the_end;
|
|
|
|
|
2016-10-27 13:10:58 +00:00
|
|
|
if (state->regs) {
|
|
|
|
printk_deferred_once(KERN_WARNING
|
|
|
|
"WARNING: kernel stack regs at %p in %s:%d has bad 'bp' value %p\n",
|
|
|
|
state->regs, state->task->comm,
|
2017-04-12 18:47:10 +00:00
|
|
|
state->task->pid, next_bp);
|
2017-04-18 13:12:58 +00:00
|
|
|
unwind_dump(state);
|
2016-10-27 13:10:58 +00:00
|
|
|
} else {
|
|
|
|
printk_deferred_once(KERN_WARNING
|
|
|
|
"WARNING: kernel stack frame pointer at %p in %s:%d has bad value %p\n",
|
|
|
|
state->bp, state->task->comm,
|
2017-04-12 18:47:10 +00:00
|
|
|
state->task->pid, next_bp);
|
2017-04-18 13:12:58 +00:00
|
|
|
unwind_dump(state);
|
2016-10-27 13:10:58 +00:00
|
|
|
}
|
2016-10-20 16:34:40 +00:00
|
|
|
the_end:
|
|
|
|
state->stack_info.type = STACK_TYPE_UNKNOWN;
|
|
|
|
return false;
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(unwind_next_frame);
|
|
|
|
|
|
|
|
void __unwind_start(struct unwind_state *state, struct task_struct *task,
|
|
|
|
struct pt_regs *regs, unsigned long *first_frame)
|
|
|
|
{
|
2017-04-12 18:47:10 +00:00
|
|
|
unsigned long *bp;
|
2016-10-20 16:34:40 +00:00
|
|
|
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
memset(state, 0, sizeof(*state));
|
|
|
|
state->task = task;
|
2017-04-12 18:47:12 +00:00
|
|
|
state->got_irq = (regs);
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
|
2017-04-12 18:47:10 +00:00
|
|
|
/* Don't even attempt to start from user mode regs: */
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
if (regs && user_mode(regs)) {
|
|
|
|
state->stack_info.type = STACK_TYPE_UNKNOWN;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:34:40 +00:00
|
|
|
bp = get_frame_pointer(task, regs);
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
|
2019-03-01 03:12:00 +00:00
|
|
|
/*
|
|
|
|
* If we crash with IP==0, the last successfully executed instruction
|
|
|
|
* was probably an indirect function call with a NULL function pointer.
|
|
|
|
* That means that SP points into the middle of an incomplete frame:
|
|
|
|
* *SP is a return pointer, and *(SP-sizeof(unsigned long)) is where we
|
|
|
|
* would have written a frame pointer if we hadn't crashed.
|
|
|
|
* Pretend that the frame is complete and that BP points to it, but save
|
|
|
|
* the real BP so that we can use it when looking for the next frame.
|
|
|
|
*/
|
2019-05-07 21:25:54 +00:00
|
|
|
if (regs && regs->ip == 0 && (unsigned long *)regs->sp >= first_frame) {
|
2019-03-01 03:12:00 +00:00
|
|
|
state->next_bp = bp;
|
2019-05-07 21:25:54 +00:00
|
|
|
bp = ((unsigned long *)regs->sp) - 1;
|
2019-03-01 03:12:00 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 18:47:10 +00:00
|
|
|
/* Initialize stack info and make sure the frame data is accessible: */
|
|
|
|
get_stack_info(bp, state->task, &state->stack_info,
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
&state->stack_mask);
|
2017-04-12 18:47:10 +00:00
|
|
|
update_stack_state(state, bp);
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The caller can provide the address of the first frame directly
|
|
|
|
* (first_frame) or indirectly (regs->sp) to indicate which stack frame
|
|
|
|
* to start unwinding at. Skip ahead until we reach it.
|
|
|
|
*/
|
|
|
|
while (!unwind_done(state) &&
|
|
|
|
(!on_stack(&state->stack_info, first_frame, sizeof(long)) ||
|
2019-03-01 03:12:00 +00:00
|
|
|
(state->next_bp == NULL && state->bp < first_frame)))
|
x86/unwind: Add new unwind interface and implementations
The x86 stack dump code is a bit of a mess. dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.
Also there are some upcoming features which will need more changes to
the stack dump code, including the printing of stack pt_regs, reliable
stack detection for live patching, and a DWARF unwinder. Each of those
features would at least need more callbacks and/or callback interfaces,
resulting in a much bigger mess than what we have today.
Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.
The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:
https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com
It's also similar to the libunwind API:
http://www.nongnu.org/libunwind/man/libunwind(3).html
Some if its advantages:
- Simplicity: no more callback sprawl and less code duplication.
- Flexibility: it allows the caller to stop and inspect the stack state
at each step in the unwinding process.
- Modularity: the unwinder code, console stack dump code, and stack
metadata analysis code are all better separated so that changing one
of them shouldn't have much of an impact on any of the others.
Two implementations are added which conform to the new unwind interface:
- The frame pointer unwinder which is used for CONFIG_FRAME_POINTER=y.
- The "guess" unwinder which is used for CONFIG_FRAME_POINTER=n. This
isn't an "unwinder" per se. All it does is scan the stack for kernel
text addresses. But with no frame pointers, guesses are better than
nothing in most cases.
Suggested-by: Andy Lutomirski <luto@amacapital.net>
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: Byungchul Park <byungchul.park@lge.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/6dc2f909c47533d213d0505f0a113e64585bec82.1474045023.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-09-16 19:18:12 +00:00
|
|
|
unwind_next_frame(state);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(__unwind_start);
|