Skip to contentSkip to conversation

i386: show_registers(): try harder to print failing code

PATCH In review Chuck Ebbert 3 participants 3 messages Jul 18, 2006 – Jul 19, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i386: show_registers(): try harder to print failing code

show_registers() tries to dump failing code starting 43 bytes before the offending instruction, but this address can be bad, for example in a device driver where the failing instruction is less than 43 bytes from the start of the driver's code. When that happens, try to dump code starting at the failing instruction instead of printing no code at all.

arch/i386/kernel/traps.c +8 -3
@@ -307,6 +307,8 @@ void show_registers(struct pt_regs *regs
 	 */
 	if (in_kernel) {
 		u8 __user *eip;
+		int code_bytes = 64;
+		unsigned char c;
 
 		printk("\n" KERN_EMERG "Stack: ");
 		show_stack_log_lvl(NULL, regs, (unsigned long *)esp, KERN_EMERG);
@@ -314,9 +316,12 @@ void show_registers(struct pt_regs *regs
 		printk(KERN_EMERG "Code: ");
 
 		eip = (u8 __user *)regs->eip - 43;
-		for (i = 0; i < 64; i++, eip++) {
-			unsigned char c;
-
+		if (eip < (u8 __user *)PAGE_OFFSET || __get_user(c, eip)) {
+			/* try starting at EIP */
+			eip = (u8 __user *)regs->eip;
+			code_bytes = 32;
+		}
+		for (i = 0; i < code_bytes; i++, eip++) {
 			if (eip < (u8 __user *)PAGE_OFFSET || __get_user(c, eip)) {
 				printk(" Bad EIP value.");
 				break;
Signature · 1 line
Chuck
#1 lore raw
Quoted 7 lines · Chuck Ebbert

show_registers() tries to dump failing code starting 43 bytes before the offending instruction, but this address can be bad, for example in a device driver where the failing instruction is less than 43 bytes from the start of the driver's code. When that happens, try to dump code starting at the failing instruction instead of printing no code at all.

Shouldn't the kernel be printing some info noting that this fallback is in use then? Or will that be completely obvious and I'm just not able to see that?

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#2 lore raw
Quoted 11 lines · "Jesper Juhl" (on Wed, 19 Jul 2006 00:12:32 +0200) wrote:
Quoted 7 lines · Chuck Ebbert

show_registers() tries to dump failing code starting 43 bytes before the offending instruction, but this address can be bad, for example in a device driver where the failing instruction is less than 43 bytes from the start of the driver's code. When that happens, try to dump code starting at the failing instruction instead of printing no code at all.

Shouldn't the kernel be printing some info noting that this fallback is in use then? Or will that be completely obvious and I'm just not able to see that?

The instruction at the EIP is bracketed, which makes it obvious if you got any preceding instructions or not.