Skip to content

Commit bb5e5ce

Browse files
jpoimboeingomolnar
authored andcommitted
x86/dumpstack: Remove kernel text addresses from stack dump
Printing kernel text addresses in stack dumps is of questionable value, especially now that address randomization is becoming common. It can be a security issue because it leaks kernel addresses. It also affects the usefulness of the stack dump. Linus says: "I actually spend time cleaning up commit messages in logs, because useless data that isn't actually information (random hex numbers) is actively detrimental. It makes commit logs less legible. It also makes it harder to parse dumps. It's not useful. That makes it actively bad. I probably look at more oops reports than most people. I have not found the hex numbers useful for the last five years, because they are just randomized crap. The stack content thing just makes code scroll off the screen etc, for example." The only real downside to removing these addresses is that they can be used to disambiguate duplicate symbol names. However such cases are rare, and the context of the stack dump should be enough to be able to figure it out. There's now a 'faddr2line' script which can be used to convert a function address to a file name and line: $ ./scripts/faddr2line ~/k/vmlinux write_sysrq_trigger+0x51/0x60 write_sysrq_trigger+0x51/0x60: write_sysrq_trigger at drivers/tty/sysrq.c:1098 Or gdb can be used: $ echo "list *write_sysrq_trigger+0x51" |gdb ~/k/vmlinux |grep "is in" (gdb) 0xffffffff815b5d83 is in driver_probe_device (/home/jpoimboe/git/linux/drivers/base/dd.c:378). (But note that when there are duplicate symbol names, gdb will only show the first symbol it finds. faddr2line is recommended over gdb because it handles duplicates and it also does function size checking.) Here's an example of what a stack dump looks like after this change: BUG: unable to handle kernel NULL pointer dereference at (null) IP: sysrq_handle_crash+0x45/0x80 PGD 36bfa067 [ 29.650644] PUD 7aca3067 Oops: 0002 [raspberrypi#1] PREEMPT SMP Modules linked in: ... CPU: 1 PID: 786 Comm: bash Tainted: G E 4.9.0-rc1+ raspberrypi#1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.9.1-1.fc24 04/01/2014 task: ffff880078582a40 task.stack: ffffc90000ba8000 RIP: 0010:sysrq_handle_crash+0x45/0x80 RSP: 0018:ffffc90000babdc8 EFLAGS: 00010296 RAX: ffff880078582a40 RBX: 0000000000000063 RCX: 0000000000000001 RDX: 0000000000000001 RSI: 0000000000000000 RDI: 0000000000000292 RBP: ffffc90000babdc8 R08: 0000000b31866061 R09: 0000000000000000 R10: 0000000000000001 R11: 0000000000000000 R12: 0000000000000000 R13: 0000000000000007 R14: ffffffff81ee8680 R15: 0000000000000000 FS: 00007ffb43869700(0000) GS:ffff88007d400000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 000000007a3e9000 CR4: 00000000001406e0 Stack: ffffc90000babe00 ffffffff81572d08 ffffffff81572bd5 0000000000000002 0000000000000000 ffff880079606600 00007ffb4386e000 ffffc90000babe20 ffffffff81573201 ffff880036a3fd00 fffffffffffffffb ffffc90000babe40 Call Trace: __handle_sysrq+0x138/0x220 ? __handle_sysrq+0x5/0x220 write_sysrq_trigger+0x51/0x60 proc_reg_write+0x42/0x70 __vfs_write+0x37/0x140 ? preempt_count_sub+0xa1/0x100 ? __sb_start_write+0xf5/0x210 ? vfs_write+0x183/0x1a0 vfs_write+0xb8/0x1a0 SyS_write+0x58/0xc0 entry_SYSCALL_64_fastpath+0x1f/0xc2 RIP: 0033:0x7ffb42f55940 RSP: 002b:00007ffd33bb6b18 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 RAX: ffffffffffffffda RBX: 0000000000000046 RCX: 00007ffb42f55940 RDX: 0000000000000002 RSI: 00007ffb4386e000 RDI: 0000000000000001 RBP: 0000000000000011 R08: 00007ffb4321ea40 R09: 00007ffb43869700 R10: 00007ffb43869700 R11: 0000000000000246 R12: 0000000000778a10 R13: 00007ffd33bb5c00 R14: 0000000000000007 R15: 0000000000000010 Code: 34 e8 d0 34 bc ff 48 c7 c2 3b 2b 57 81 be 01 00 00 00 48 c7 c7 e0 dd e5 81 e8 a8 55 ba ff c7 05 0e 3f de 00 01 00 00 00 0f ae f8 <c6> 04 25 00 00 00 00 01 5d c3 e8 4c 49 bc ff 84 c0 75 c3 48 c7 RIP: sysrq_handle_crash+0x45/0x80 RSP: ffffc90000babdc8 CR2: 0000000000000000 Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/69329cb29b8f324bb5fcea14d61d224807fb6488.1477405374.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent efdb416 commit bb5e5ce

6 files changed

Lines changed: 13 additions & 26 deletions

File tree

‎arch/x86/include/asm/kdebug.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ enum die_val {
2121
DIE_NMIUNKNOWN,
2222
};
2323

24-
extern void printk_address(unsigned long address);
2524
extern void die(const char *, struct pt_regs *,long);
2625
extern int __must_check __die(const char *, struct pt_regs *, long);
2726
extern void show_stack_regs(struct pt_regs *regs);

‎arch/x86/kernel/dumpstack.c‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,7 @@ static void printk_stack_address(unsigned long address, int reliable,
4646
char *log_lvl)
4747
{
4848
touch_nmi_watchdog();
49-
printk("%s [<%p>] %s%pB\n",
50-
log_lvl, (void *)address, reliable ? "" : "? ",
51-
(void *)address);
52-
}
53-
54-
void printk_address(unsigned long address)
55-
{
56-
pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
49+
printk("%s %s%pB\n", log_lvl, reliable ? "" : "? ", (void *)address);
5750
}
5851

5952
void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
@@ -275,14 +268,11 @@ int __die(const char *str, struct pt_regs *regs, long err)
275268
sp = kernel_stack_pointer(regs);
276269
savesegment(ss, ss);
277270
}
278-
printk(KERN_EMERG "EIP: [<%08lx>] ", regs->ip);
279-
print_symbol("%s", regs->ip);
280-
printk(" SS:ESP %04x:%08lx\n", ss, sp);
271+
printk(KERN_EMERG "EIP: %pS SS:ESP: %04x:%08lx\n",
272+
(void *)regs->ip, ss, sp);
281273
#else
282274
/* Executive summary in case the oops scrolled away */
283-
printk(KERN_ALERT "RIP ");
284-
printk_address(regs->ip);
285-
printk(" RSP <%016lx>\n", regs->sp);
275+
printk(KERN_ALERT "RIP: %pS RSP: %016lx\n", (void *)regs->ip, regs->sp);
286276
#endif
287277
return 0;
288278
}

‎arch/x86/kernel/process_32.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ void __show_regs(struct pt_regs *regs, int all)
7272
savesegment(gs, gs);
7373
}
7474

75-
printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
76-
(u16)regs->cs, regs->ip, regs->flags,
77-
smp_processor_id());
78-
print_symbol("EIP is at %s\n", regs->ip);
75+
printk(KERN_DEFAULT "EIP: %pS\n", (void *)regs->ip);
76+
printk(KERN_DEFAULT "EFLAGS: %08lx CPU: %d\n", regs->flags,
77+
smp_processor_id());
7978

8079
printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
8180
regs->ax, regs->bx, regs->cx, regs->dx);

‎arch/x86/kernel/process_64.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ void __show_regs(struct pt_regs *regs, int all)
6161
unsigned int fsindex, gsindex;
6262
unsigned int ds, cs, es;
6363

64-
printk(KERN_DEFAULT "RIP: %04lx:[<%016lx>] %pS\n", regs->cs & 0xffff,
65-
regs->ip, (void *)regs->ip);
64+
printk(KERN_DEFAULT "RIP: %04lx:%pS\n", regs->cs & 0xffff,
65+
(void *)regs->ip);
6666
printk(KERN_DEFAULT "RSP: %04lx:%016lx EFLAGS: %08lx", regs->ss,
67-
regs->sp, regs->flags);
67+
regs->sp, regs->flags);
6868
if (regs->orig_ax != -1)
6969
pr_cont(" ORIG_RAX: %016lx\n", regs->orig_ax);
7070
else

‎arch/x86/mm/fault.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
679679
printk(KERN_CONT "paging request");
680680

681681
printk(KERN_CONT " at %p\n", (void *) address);
682-
printk(KERN_ALERT "IP:");
683-
printk_address(regs->ip);
682+
printk(KERN_ALERT "IP: %pS\n", (void *)regs->ip);
684683

685684
dump_pagetable(address);
686685
}

‎arch/x86/platform/uv/uv_nmi.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ static void uv_nmi_dump_cpu_ip_hdr(void)
387387
/* Dump Instruction Pointer info */
388388
static void uv_nmi_dump_cpu_ip(int cpu, struct pt_regs *regs)
389389
{
390-
pr_info("UV: %4d %6d %-32.32s ", cpu, current->pid, current->comm);
391-
printk_address(regs->ip);
390+
pr_info("UV: %4d %6d %-32.32s %pS",
391+
cpu, current->pid, current->comm, (void *)regs->ip);
392392
}
393393

394394
/*

0 commit comments

Comments
 (0)