aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJann Horn <jannh@google.com>2018-08-31 15:41:51 -0400
committerThomas Gleixner <tglx@linutronix.de>2018-09-06 08:33:12 -0400
commit9fe6299dde587788f245e9f7a5a1b296fad4e8c7 (patch)
tree45fd4582b522ebfe51c990470f409ba66ba22f17
parent17f6bac2249356c795339e03a0742cd79be3cab8 (diff)
x86/process: Don't mix user/kernel regs in 64bit __show_regs()
When the kernel.print-fatal-signals sysctl has been enabled, a simple userspace crash will cause the kernel to write a crash dump that contains, among other things, the kernel gsbase into dmesg. As suggested by Andy, limit output to pt_regs, FS_BASE and KERNEL_GS_BASE in this case. This also moves the bitness-specific logic from show_regs() into process_{32,64}.c. Fixes: 45807a1df9f5 ("vdso: print fatal signals") Signed-off-by: Jann Horn <jannh@google.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bpetkov@suse.de> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20180831194151.123586-1-jannh@google.com
-rw-r--r--arch/x86/include/asm/kdebug.h12
-rw-r--r--arch/x86/kernel/dumpstack.c11
-rw-r--r--arch/x86/kernel/process_32.c4
-rw-r--r--arch/x86/kernel/process_64.c12
4 files changed, 26 insertions, 13 deletions
diff --git a/arch/x86/include/asm/kdebug.h b/arch/x86/include/asm/kdebug.h
index 395c9631e000..75f1e35e7c15 100644
--- a/arch/x86/include/asm/kdebug.h
+++ b/arch/x86/include/asm/kdebug.h
@@ -22,10 +22,20 @@ enum die_val {
22 DIE_NMIUNKNOWN, 22 DIE_NMIUNKNOWN,
23}; 23};
24 24
25enum show_regs_mode {
26 SHOW_REGS_SHORT,
27 /*
28 * For when userspace crashed, but we don't think it's our fault, and
29 * therefore don't print kernel registers.
30 */
31 SHOW_REGS_USER,
32 SHOW_REGS_ALL
33};
34
25extern void die(const char *, struct pt_regs *,long); 35extern void die(const char *, struct pt_regs *,long);
26extern int __must_check __die(const char *, struct pt_regs *, long); 36extern int __must_check __die(const char *, struct pt_regs *, long);
27extern void show_stack_regs(struct pt_regs *regs); 37extern void show_stack_regs(struct pt_regs *regs);
28extern void __show_regs(struct pt_regs *regs, int all); 38extern void __show_regs(struct pt_regs *regs, enum show_regs_mode);
29extern void show_iret_regs(struct pt_regs *regs); 39extern void show_iret_regs(struct pt_regs *regs);
30extern unsigned long oops_begin(void); 40extern unsigned long oops_begin(void);
31extern void oops_end(unsigned long, struct pt_regs *, int signr); 41extern void oops_end(unsigned long, struct pt_regs *, int signr);
diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
index f56895106ccf..2b5886401e5f 100644
--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -146,7 +146,7 @@ static void show_regs_if_on_stack(struct stack_info *info, struct pt_regs *regs,
146 * they can be printed in the right context. 146 * they can be printed in the right context.
147 */ 147 */
148 if (!partial && on_stack(info, regs, sizeof(*regs))) { 148 if (!partial && on_stack(info, regs, sizeof(*regs))) {
149 __show_regs(regs, 0); 149 __show_regs(regs, SHOW_REGS_SHORT);
150 150
151 } else if (partial && on_stack(info, (void *)regs + IRET_FRAME_OFFSET, 151 } else if (partial && on_stack(info, (void *)regs + IRET_FRAME_OFFSET,
152 IRET_FRAME_SIZE)) { 152 IRET_FRAME_SIZE)) {
@@ -344,7 +344,7 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
344 oops_exit(); 344 oops_exit();
345 345
346 /* Executive summary in case the oops scrolled away */ 346 /* Executive summary in case the oops scrolled away */
347 __show_regs(&exec_summary_regs, true); 347 __show_regs(&exec_summary_regs, SHOW_REGS_ALL);
348 348
349 if (!signr) 349 if (!signr)
350 return; 350 return;
@@ -407,14 +407,9 @@ void die(const char *str, struct pt_regs *regs, long err)
407 407
408void show_regs(struct pt_regs *regs) 408void show_regs(struct pt_regs *regs)
409{ 409{
410 bool all = true;
411
412 show_regs_print_info(KERN_DEFAULT); 410 show_regs_print_info(KERN_DEFAULT);
413 411
414 if (IS_ENABLED(CONFIG_X86_32)) 412 __show_regs(regs, user_mode(regs) ? SHOW_REGS_USER : SHOW_REGS_ALL);
415 all = !user_mode(regs);
416
417 __show_regs(regs, all);
418 413
419 /* 414 /*
420 * When in-kernel, we also print out the stack at the time of the fault.. 415 * When in-kernel, we also print out the stack at the time of the fault..
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index 2924fd447e61..5046a3c9dec2 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -59,7 +59,7 @@
59#include <asm/intel_rdt_sched.h> 59#include <asm/intel_rdt_sched.h>
60#include <asm/proto.h> 60#include <asm/proto.h>
61 61
62void __show_regs(struct pt_regs *regs, int all) 62void __show_regs(struct pt_regs *regs, enum show_regs_mode mode)
63{ 63{
64 unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L; 64 unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L;
65 unsigned long d0, d1, d2, d3, d6, d7; 65 unsigned long d0, d1, d2, d3, d6, d7;
@@ -85,7 +85,7 @@ void __show_regs(struct pt_regs *regs, int all)
85 printk(KERN_DEFAULT "DS: %04x ES: %04x FS: %04x GS: %04x SS: %04x EFLAGS: %08lx\n", 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); 86 (u16)regs->ds, (u16)regs->es, (u16)regs->fs, gs, ss, regs->flags);
87 87
88 if (!all) 88 if (mode != SHOW_REGS_ALL)
89 return; 89 return;
90 90
91 cr0 = read_cr0(); 91 cr0 = read_cr0();
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index a451bc374b9b..ea5ea850348d 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -62,7 +62,7 @@
62__visible DEFINE_PER_CPU(unsigned long, rsp_scratch); 62__visible DEFINE_PER_CPU(unsigned long, rsp_scratch);
63 63
64/* Prints also some state that isn't saved in the pt_regs */ 64/* Prints also some state that isn't saved in the pt_regs */
65void __show_regs(struct pt_regs *regs, int all) 65void __show_regs(struct pt_regs *regs, enum show_regs_mode mode)
66{ 66{
67 unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs; 67 unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
68 unsigned long d0, d1, d2, d3, d6, d7; 68 unsigned long d0, d1, d2, d3, d6, d7;
@@ -87,9 +87,17 @@ void __show_regs(struct pt_regs *regs, int all)
87 printk(KERN_DEFAULT "R13: %016lx R14: %016lx R15: %016lx\n", 87 printk(KERN_DEFAULT "R13: %016lx R14: %016lx R15: %016lx\n",
88 regs->r13, regs->r14, regs->r15); 88 regs->r13, regs->r14, regs->r15);
89 89
90 if (!all) 90 if (mode == SHOW_REGS_SHORT)
91 return; 91 return;
92 92
93 if (mode == SHOW_REGS_USER) {
94 rdmsrl(MSR_FS_BASE, fs);
95 rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
96 printk(KERN_DEFAULT "FS: %016lx GS: %016lx\n",
97 fs, shadowgs);
98 return;
99 }
100
93 asm("movl %%ds,%0" : "=r" (ds)); 101 asm("movl %%ds,%0" : "=r" (ds));
94 asm("movl %%cs,%0" : "=r" (cs)); 102 asm("movl %%cs,%0" : "=r" (cs));
95 asm("movl %%es,%0" : "=r" (es)); 103 asm("movl %%es,%0" : "=r" (es));