x86/dumpstack: Fix printk_address for direct addresses
authorJiri Slaby <jslaby@suse.cz>
Fri, 25 Oct 2013 13:06:58 +0000 (15:06 +0200)
committerJiri Slaby <jslaby@suse.cz>
Wed, 12 Mar 2014 12:25:40 +0000 (13:25 +0100)
commit 5f01c98859073cb512b01d4fad74b5f4e047be0b upstream.

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>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
arch/x86/include/asm/kdebug.h
arch/x86/kernel/dumpstack.c
arch/x86/kernel/process_64.c
arch/x86/mm/fault.c

index 2c37aadcbc350a48756e05e00b9b227eb2808d2b..32ce71375b212cd0fc8fa5d847d09c1d7aa5bc6b 100644 (file)
@@ -21,7 +21,7 @@ enum die_val {
        DIE_NMIUNKNOWN,
 };
 
-extern void printk_address(unsigned long address, int reliable);
+extern void printk_address(unsigned long address);
 extern void die(const char *, struct pt_regs *,long);
 extern int __must_check __die(const char *, struct pt_regs *, long);
 extern void show_trace(struct task_struct *t, struct pt_regs *regs,
index deb6421c9e69d6cae32422e99fd6b77477762707..d9c12d3022a70c68e3f69d4cf2d68bdc10123010 100644 (file)
@@ -25,12 +25,17 @@ unsigned int code_bytes = 64;
 int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE;
 static int die_counter;
 
-void printk_address(unsigned long address, int reliable)
+static void printk_stack_address(unsigned long address, int reliable)
 {
        pr_cont(" [<%p>] %s%pB\n",
                (void *)address, reliable ? "" : "? ", (void *)address);
 }
 
+void printk_address(unsigned long address)
+{
+       pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
+}
+
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 static void
 print_ftrace_graph_addr(unsigned long addr, void *data,
@@ -151,7 +156,7 @@ static void print_trace_address(void *data, unsigned long addr, int reliable)
 {
        touch_nmi_watchdog();
        printk(data);
-       printk_address(addr, reliable);
+       printk_stack_address(addr, reliable);
 }
 
 static const struct stacktrace_ops print_trace_ops = {
@@ -281,7 +286,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
 #else
        /* Executive summary in case the oops scrolled away */
        printk(KERN_ALERT "RIP ");
-       printk_address(regs->ip, 1);
+       printk_address(regs->ip);
        printk(" RSP <%016lx>\n", regs->sp);
 #endif
        return 0;
index bb1dc51bab05649c4eb2e48ddbb23840c4a598a8..8e9fe8dfd37bfec6555374f613c840afb0e45a06 100644 (file)
@@ -63,7 +63,7 @@ void __show_regs(struct pt_regs *regs, int all)
        unsigned int ds, cs, es;
 
        printk(KERN_DEFAULT "RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->ip);
-       printk_address(regs->ip, 1);
+       printk_address(regs->ip);
        printk(KERN_DEFAULT "RSP: %04lx:%016lx  EFLAGS: %08lx\n", regs->ss,
                        regs->sp, regs->flags);
        printk(KERN_DEFAULT "RAX: %016lx RBX: %016lx RCX: %016lx\n",
index d8b1ff68dbb9366692ba2502286172692fb36ef5..5b90bbcad9f63d1f64ddf66a6adfd232e345bd36 100644 (file)
@@ -596,7 +596,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
 
        printk(KERN_CONT " at %p\n", (void *) address);
        printk(KERN_ALERT "IP:");
-       printk_address(regs->ip, 1);
+       printk_address(regs->ip);
 
        dump_pagetable(address);
 }