reliable stack trace support (i386)
PATCH 3/3 reliable stack trace support (i386)
These are the i386-specific pieces to enable reliable stack traces. This is going to be even more useful once CFI annotations get added to he assembly code, namely to entry.S (a patch for that had been submitted several times).
arch/i386/kernel/entry.S +29 -0
@@ -663,6 +663,35 @@ ENTRY(spurious_interrupt_bug) pushl $do_spurious_interrupt_bug jmp error_code +#ifdef CONFIG_STACK_UNWIND +ENTRY(arch_unwind_init_running) + movl 4(%esp), %edx + movl (%esp), %ecx + leal 4(%esp), %eax + movl %ebx, EBX(%edx) + xorl %ebx, %ebx + movl %ebx, ECX(%edx) + movl %ebx, EDX(%edx) + movl %esi, ESI(%edx) + movl %edi, EDI(%edx) + movl %ebp, EBP(%edx) + movl %ebx, EAX(%edx) + movl $__USER_DS, DS(%edx) + movl $__USER_DS, ES(%edx) + movl %ebx, ORIG_EAX(%edx) + movl %ecx, EIP(%edx) + movl 12(%esp), %ecx + movl $__KERNEL_CS, CS(%edx) + movl %ebx, EFLAGS(%edx) + movl %eax, OLDESP(%edx) + movl 8(%esp), %eax + movl %ecx, 8(%esp) + movl EBX(%edx), %ebx + movl $__KERNEL_DS, OLDSS(%edx) + jmpl *%eax +ENDPROC(arch_unwind_init_running) +#endif + .section .rodata,"a" #include "syscall_table.S"
arch/i386/kernel/process.c +1 -1
@@ -312,7 +312,7 @@ void show_regs(struct pt_regs * regs) cr3 =read_cr3 (); cr4 =read_cr4_safe ();printk ("CR0: %08lx CR2: %08lx CR3: %08lx CR4: %08lx\n" , cr0, cr2, cr3, cr4); -show_trace (NULL , ®s->esp); +show_trace (NULL , regs, ®s->esp); }/*
arch/i386/kernel/traps.c +39 -10
100 lines not on this page · raw message
arch/i386/kernel/vmlinux.lds.S +9 -0
@@ -64,6 +64,15 @@ SECTIONS .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) { *(.data.read_mostly) } _edata = .; /* End of data section */ +#ifdef CONFIG_STACK_UNWIND + . = ALIGN(4); + .eh_frame : AT(ADDR(.eh_frame) - LOAD_OFFSET) { + __start_unwind = .; + *(.eh_frame) + __end_unwind = .; + } +#endif + . = ALIGN(THREAD_SIZE); /* init_task */ .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) { *(.data.init_task)
include/asm-i386/processor.h +1 -1
@@ -555,7 +555,7 @@ extern void prepare_to_copy(struct task_extern int kernel_thread (int (*fn)(void *),void * arg,unsigned long flags);extern unsigned long thread_saved_pc (struct task_struct *tsk); -void show_trace (struct task_struct *task,unsigned long *stack); +void show_trace (struct task_struct *task,struct pt_regs *regs,unsigned long *stack);unsigned long get_wchan (struct task_struct *p);
include/asm-i386/unwind.h +97 -0
97 lines not on this page · raw message
lib/Kconfig.debug +1 -1
@@ -199,7 +199,7 @@ config UNWIND_INFO config STACK_UNWIND bool "Stack unwind support" depends on UNWIND_INFO - depends on X86_64 + depends on X86 help This enables more precise stack traces, omitting all unrelated occurrences of pointers into kernel code from the dump.
include/asm-i386/unwind.h line 29
Quoted 13 lines · Jan Beulich
These are the i386-specific pieces to enable reliable stack traces. This is going to be even more useful once CFI annotations get added to he assembly code, namely to
entry.S(a patch for that had been submitted several times).include/asm-i386/unwind.h +9
-0+#define UNW_PC (frame) (frame)->regs.eip +#define UNW_SP (frame) (frame)->regs.esp +#ifdef CONFIG_FRAME_POINTER +#define UNW_FP (frame) (frame)->regs.ebp +#define FRAME_RETADDR_OFFSET 4 +#define FRAME_LINK_OFFSET 0 +#define STACK_BOTTOM (tsk) (((tsk)->thread.esp0 - 1) & ~(THREAD_SIZE - 1)) +#define STACK_TOP (tsk) ((tsk)->thread.esp0) +#endif
style: i'd suggest to improve readability by aligning these.
include/asm-i386/unwind.h line 64
Quoted 11 lines
include/asm-i386/unwind.h +11
-0+static inline void +arch_unw_init_blocked (struct unwind_frame_info *info) +{ +memset (&info->regs,0 ,sizeof (info->regs)); + info->regs.eip = info->task->thread.eip; + info->regs.xcs = __KERNEL_CS; +__get_user (info->regs.ebp, (long *)info->task->thread.esp); + info->regs.esp = info->task->thread.esp; + info->regs.xss = __KERNEL_DS; + info->regs.xds = __USER_DS; + info->regs.xes = __USER_DS;
hm, arent you using this from within show_trace()? In that case we shouldnt do a __get_user() i think, we might be in an arbitrary context
...
include/asm-i386/unwind.h line 80
Quoted 9 lines
include/asm-i386/unwind.h +9
-0+static inline int +arch_unw_user_mode (const struct unwind_frame_info *info) +{ +#if 0 /* This can only work when selector register and EFLAGS saves/restores +are properly annotated (and tracked in UNW_REGISTER_INFO). */ +return user_mode_vm (&info->regs); +#else +return info->regs.eip <PAGE_OFFSET ; +#endif
same here as for x86_64: is this condition safe? Userspace can provoke an EIP of >= PAGE_OFFSET by for example jumping to the vsyscall page.
Ingo
Quoted 3 lines · Jan Beulich
These are the i386-specific pieces to enable reliable stack traces. This is going to be even more useful once CFI annotations get added to he assembly code, namely to
entry.S(a patch for that had been submitted several times).
Yes we should merge that. Can you resend it please?
Quoted 1 line
+static asmlinkage void
show_trace_unwind(struct unwind_frame_info *info, void *log_lvl)
static asmlinkage ?
include/asm-i386/unwind.h line 29
Quoted 9 lines
include/asm-i386/unwind.h +9
-0+#define UNW_PC (frame) (frame)->regs.eip +#define UNW_SP (frame) (frame)->regs.esp +#ifdef CONFIG_FRAME_POINTER +#define UNW_FP (frame) (frame)->regs.ebp +#define FRAME_RETADDR_OFFSET 4 +#define FRAME_LINK_OFFSET 0 +#define STACK_BOTTOM (tsk) (((tsk)->thread.esp0 - 1) & ~(THREAD_SIZE - 1)) +#define STACK_TOP (tsk) ((tsk)->thread.esp0) +#endif
Same comments as for x86-64
-Andi
Quoted 15 lines
include/asm-i386/unwind.h line 64
Quoted 12 lines
include/asm-i386/unwind.h +11
-0+static inline void +arch_unw_init_blocked (struct unwind_frame_info *info) +{ +memset (&info->regs,0 ,sizeof (info->regs)); + info->regs.eip = info->task->thread.eip; + info->regs.xcs = __KERNEL_CS; +__get_user (info->regs.ebp, (long *)info->task->thread.esp); + info->regs.esp = info->task->thread.esp; + info->regs.xss = __KERNEL_DS; + info->regs.xds = __USER_DS; + info->regs.xes = __USER_DS;hm, arent you using this from within
show_trace()? In that case we shouldnt do a__get_user()i think, we might be in an arbitrary context
Should be ok. We already do this in some parts of oopsing and the page fault handler can handle it as long as there is an exception entry (which is there for this case)
Quoted 14 lines
...
include/asm-i386/unwind.h line 80
Quoted 9 lines
include/asm-i386/unwind.h +9
-0+static inline int +arch_unw_user_mode (const struct unwind_frame_info *info) +{ +#if 0 /* This can only work when selector register and EFLAGS saves/restores +are properly annotated (and tracked in UNW_REGISTER_INFO). */ +return user_mode_vm (&info->regs); +#else +return info->regs.eip <PAGE_OFFSET ; +#endif same here as for
x86_64: is this condition safe? Userspace can provoke an EIP of >=PAGE_OFFSETby for example jumping to the vsyscall page.
Good point, it's probably not. Especially since we already have a user_mode() macro
-Andi
Quoted 3 lines
Quoted 1 line
+static asmlinkage void
show_trace_unwind(struct unwind_frame_info *info, void *log_lvl)static asmlinkage ?
Yes, as it's being used as a callback from assembly.
Jan