Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/dumpstack: Fix printk_address for direct addresses

Consider a kernel crash in a module, simulated the following way:

static int my_init(void)
{
char *map = (void *)0x5;
*map = 3;
return 0;
}
module_init(my_init);

When we turn off FRAME_POINTERs, the very first instruction in
that function causes a BUG. The problem is that we print IP in
the BUG report using %pB (from printk_address). And %pB
decrements the pointer by one to fix printing addresses of
functions with tail calls.

This was added in commit 71f9e59800e5ad4 ("x86, dumpstack: Use
%pB format specifier for stack trace") to fix the call stack
printouts.

So instead of correct output:

BUG: unable to handle kernel NULL pointer dereference at 0000000000000005
IP: [<ffffffffa01ac000>] my_init+0x0/0x10 [pb173]

We get:

BUG: unable to handle kernel NULL pointer dereference at 0000000000000005
IP: [<ffffffffa0152000>] 0xffffffffa0151fff

To fix that, we use %pS only for stack addresses printouts (via
newly added printk_stack_address) and %pB for regs->ip (via
printk_address). I.e. we revert to the old behaviour for all
except call stacks. And since from all those reliable is 1, we
remove that parameter from printk_address.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: joe@perches.com
Cc: jirislaby@gmail.com
Link: http://lkml.kernel.org/r/1382706418-8435-1-git-send-email-jslaby@suse.cz
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Jiri Slaby and committed by
Ingo Molnar
5f01c988 9b66bfb2

+12 -7
+1 -1
arch/x86/include/asm/kdebug.h
··· 21 21 DIE_NMIUNKNOWN, 22 22 }; 23 23 24 - extern void printk_address(unsigned long address, int reliable); 24 + extern void printk_address(unsigned long address); 25 25 extern void die(const char *, struct pt_regs *,long); 26 26 extern int __must_check __die(const char *, struct pt_regs *, long); 27 27 extern void show_trace(struct task_struct *t, struct pt_regs *regs,
+8 -3
arch/x86/kernel/dumpstack.c
··· 25 25 int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE; 26 26 static int die_counter; 27 27 28 - void printk_address(unsigned long address, int reliable) 28 + static void printk_stack_address(unsigned long address, int reliable) 29 29 { 30 30 pr_cont(" [<%p>] %s%pB\n", 31 31 (void *)address, reliable ? "" : "? ", (void *)address); 32 + } 33 + 34 + void printk_address(unsigned long address) 35 + { 36 + pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address); 32 37 } 33 38 34 39 #ifdef CONFIG_FUNCTION_GRAPH_TRACER ··· 156 151 { 157 152 touch_nmi_watchdog(); 158 153 printk(data); 159 - printk_address(addr, reliable); 154 + printk_stack_address(addr, reliable); 160 155 } 161 156 162 157 static const struct stacktrace_ops print_trace_ops = { ··· 286 281 #else 287 282 /* Executive summary in case the oops scrolled away */ 288 283 printk(KERN_ALERT "RIP "); 289 - printk_address(regs->ip, 1); 284 + printk_address(regs->ip); 290 285 printk(" RSP <%016lx>\n", regs->sp); 291 286 #endif 292 287 return 0;
+1 -1
arch/x86/kernel/process_64.c
··· 63 63 unsigned int ds, cs, es; 64 64 65 65 printk(KERN_DEFAULT "RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->ip); 66 - printk_address(regs->ip, 1); 66 + printk_address(regs->ip); 67 67 printk(KERN_DEFAULT "RSP: %04lx:%016lx EFLAGS: %08lx\n", regs->ss, 68 68 regs->sp, regs->flags); 69 69 printk(KERN_DEFAULT "RAX: %016lx RBX: %016lx RCX: %016lx\n",
+1 -1
arch/x86/mm/fault.c
··· 596 596 597 597 printk(KERN_CONT " at %p\n", (void *) address); 598 598 printk(KERN_ALERT "IP:"); 599 - printk_address(regs->ip, 1); 599 + printk_address(regs->ip); 600 600 601 601 dump_pagetable(address); 602 602 }
+1 -1
arch/x86/platform/uv/uv_nmi.c
··· 399 399 printk(KERN_DEFAULT "UV: %4d %6d %-32.32s ", 400 400 cpu, current->pid, current->comm); 401 401 402 - printk_address(regs->ip, 1); 402 + printk_address(regs->ip); 403 403 } 404 404 405 405 /* Dump this cpu's state */