Skip to content

Commit 7cccf07

Browse files
suryasaimadhuKAGA-KOKO
authored andcommitted
x86/dumpstack: Add a show_ip() function
... which shows the Instruction Pointer along with the insn bytes around it. Use it whenever rIP is printed. Drop the rIP < PAGE_OFFSET check since probe_kernel_read() can handle any address properly. Signed-off-by: Borislav Petkov <bp@suse.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andy Lutomirski <luto@amacapital.net> Link: https://lkml.kernel.org/r/20180417161124.5294-8-bp@alien8.de
1 parent ba54d85 commit 7cccf07

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

arch/x86/include/asm/stacktrace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,5 @@ static inline unsigned long caller_frame_pointer(void)
112112
}
113113

114114
void show_opcodes(u8 *rip, const char *loglvl);
115+
void show_ip(struct pt_regs *regs, const char *loglvl);
115116
#endif /* _ASM_X86_STACKTRACE_H */

arch/x86/kernel/dumpstack.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,19 @@ void show_opcodes(u8 *rip, const char *loglvl)
9494
pr_cont("\n");
9595
}
9696

97+
void show_ip(struct pt_regs *regs, const char *loglvl)
98+
{
99+
#ifdef CONFIG_X86_32
100+
printk("%sEIP: %pS\n", loglvl, (void *)regs->ip);
101+
#else
102+
printk("%sRIP: %04x:%pS\n", loglvl, (int)regs->cs, (void *)regs->ip);
103+
#endif
104+
show_opcodes((u8 *)regs->ip, loglvl);
105+
}
106+
97107
void show_iret_regs(struct pt_regs *regs)
98108
{
99-
printk(KERN_DEFAULT "RIP: %04x:%pS\n", (int)regs->cs, (void *)regs->ip);
109+
show_ip(regs, KERN_DEFAULT);
100110
printk(KERN_DEFAULT "RSP: %04x:%016lx EFLAGS: %08lx", (int)regs->ss,
101111
regs->sp, regs->flags);
102112
}
@@ -392,15 +402,8 @@ void show_regs(struct pt_regs *regs)
392402
__show_regs(regs, all);
393403

394404
/*
395-
* When in-kernel, we also print out the stack and code at the
396-
* time of the fault..
405+
* When in-kernel, we also print out the stack at the time of the fault..
397406
*/
398-
if (!user_mode(regs)) {
407+
if (!user_mode(regs))
399408
show_trace_log_lvl(current, regs, NULL, KERN_DEFAULT);
400-
401-
if (regs->ip < PAGE_OFFSET)
402-
printk(KERN_DEFAULT "Code: Bad RIP value.\n");
403-
else
404-
show_opcodes((u8 *)regs->ip, KERN_DEFAULT);
405-
}
406409
}

arch/x86/kernel/process_32.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,14 @@ void __show_regs(struct pt_regs *regs, int all)
7676
savesegment(gs, gs);
7777
}
7878

79-
printk(KERN_DEFAULT "EIP: %pS\n", (void *)regs->ip);
80-
printk(KERN_DEFAULT "EFLAGS: %08lx CPU: %d\n", regs->flags,
81-
raw_smp_processor_id());
79+
show_ip(regs, KERN_DEFAULT);
8280

8381
printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
8482
regs->ax, regs->bx, regs->cx, regs->dx);
8583
printk(KERN_DEFAULT "ESI: %08lx EDI: %08lx EBP: %08lx ESP: %08lx\n",
8684
regs->si, regs->di, regs->bp, sp);
87-
printk(KERN_DEFAULT " DS: %04x ES: %04x FS: %04x GS: %04x SS: %04x\n",
88-
(u16)regs->ds, (u16)regs->es, (u16)regs->fs, gs, ss);
85+
printk(KERN_DEFAULT "DS: %04x ES: %04x FS: %04x GS: %04x SS: %04x EFLAGS: %08lx\n",
86+
(u16)regs->ds, (u16)regs->es, (u16)regs->fs, gs, ss, regs->flags);
8987

9088
if (!all)
9189
return;

0 commit comments

Comments
 (0)