Skip to contentSkip to conversation

Wrong symbol resolved for RIP on OOPS/BUG

PATCH In review Marek Majkowski 3 participants 4 messages Nov 6, 2013 – Nov 11, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Wrong symbol resolved for RIP on OOPS/BUG

"%pB" is intended for return addresses, and actually resolves the address - 1. So it should only be used for backtraces. Plain instruction addresses should use "%pS", which resolves the given address.

show_regs was using "%pB" to resolve the RIP symbol. This resolved the wrong symbol if the first instruction after a symbol created the OOPS/BUG. For example:

0000000000000049 <before>:

  49:   90                      nop
  4a:   90                      nop
  4b:   90                      nop
  4c:   90                      nop
000000000000004d <suicide>:
  4d:   ff 14 25 00 00 00 00    callq  *0x0
  54:   c3                      retq

Will produce a message saying it's "before" that crashed, not "suicide".

This problem only happens when the crash occurs in the first instruction after a symbol. Therefore it's unlikely to occur on kernels with frame pointers (CONFIG_FRAME_POINTER=y).

arch/x86/kernel/dumpstack.c +7 -1
index deb6421..4c90013 100644
@@ -27,6 +27,12 @@ static int die_counter;
 
 void printk_address(unsigned long address, int reliable)
 {
+	pr_cont(" [<%p>] %s%pS\n",
+		(void *)address, reliable ? "" : "? ", (void *)address);
+}
+
+static void printk_trace_address(unsigned long address, int reliable)
+{
 	pr_cont(" [<%p>] %s%pB\n",
 		(void *)address, reliable ? "" : "? ", (void *)address);
 }
@@ -151,7 +157,7 @@ static void print_trace_address(void *data, unsigned long addr, int reliable)
 {
 	touch_nmi_watchdog();
 	printk(data);
-	printk_address(addr, reliable);
+	printk_trace_address(addr, reliable);
 }
 
 static const struct stacktrace_ops print_trace_ops = {
Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 44 lines · Marek Majkowski

"%pB" is intended for return addresses, and actually resolves the address - 1. So it should only be used for backtraces. Plain instruction addresses should use "%pS", which resolves the given address.

show_regs was using "%pB" to resolve the RIP symbol. This resolved the wrong symbol if the first instruction after a symbol created the OOPS/BUG. For example:

0000000000000049 <before>:

  49:   90                      nop
  4a:   90                      nop
  4b:   90                      nop
  4c:   90                      nop
000000000000004d <suicide>:
  4d:   ff 14 25 00 00 00 00    callq  *0x0
  54:   c3                      retq

Will produce a message saying it's "before" that crashed, not "suicide".

This problem only happens when the crash occurs in the first instruction after a symbol. Therefore it's unlikely to occur on kernels with frame pointers (CONFIG_FRAME_POINTER=y).

arch/x86/kernel/dumpstack.c +6 -0
index deb6421..4c90013 100644
@@ -27,6 +27,12 @@ static int die_counter;
 
 void printk_address(unsigned long address, int reliable)
 {
+	pr_cont(" [<%p>] %s%pS\n",
+		(void *)address, reliable ? "" : "? ", (void *)address);
+}
+
+static void printk_trace_address(unsigned long address, int reliable)
+{
 	pr_cont(" [<%p>] %s%pB\n",
 		(void *)address, reliable ? "" : "? ", (void *)address);
 }

arch/x86/kernel/dumpstack.c static void print_trace_address(void *data, unsigned long addr, int reliable) · line 163

Quoted 8 lines
arch/x86/kernel/dumpstack.c +1 -1
@@ -151,7 +157,7 @@ static void print_trace_address(void *data, unsigned long addr, int reliable)
 {
 	touch_nmi_watchdog();
 	printk(data);
-	printk_address(addr, reliable);
+	printk_trace_address(addr, reliable);
 }
 
 static const struct stacktrace_ops print_trace_ops = {

There's a recent commit from Jiri Slaby that I think tries to address the same problem:

8d4c812a3e5f x86/dumpstack: Fix printk_address for direct addresses

You can find it in the -tip tree:

git remote add tip git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git

Thanks,

Ingo

#2 lore raw
Quoted 10 lines · Ingo Molnar

There's a recent commit from Jiri Slaby that I think tries to address the same problem:

8d4c812a3e5f x86/dumpstack: Fix printk_address for direct addresses

You can find it in the -tip tree:

git remote add tip git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git

The only difference seems to be in the handling of the "reliable" flag.

I am wondering if we shouldn't promote this patch to urgent/stable, though, since misleading oops messages could be very disruptive.

-hpa

#3 lore raw
Quoted 9 lines · H. Peter Anvin
Quoted 8 lines · Ingo Molnar

There's a recent commit from Jiri Slaby that I think tries to address the same problem:

8d4c812a3e5f x86/dumpstack: Fix printk_address for direct addresses

You can find it in the -tip tree:

Quoted 7 lines
Quoted 2 lines

git remote add tip git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git

The only difference seems to be in the handling of the "reliable" flag.

I am wondering if we shouldn't promote this patch to urgent/stable, though, since misleading oops messages could be very disruptive.

Sure, no objections.

Thanks,

Ingo