Skip to content

Commit 9fe6299

Browse files
thejhKAGA-KOKO
authored andcommitted
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: 45807a1 ("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
1 parent 17f6bac commit 9fe6299

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

arch/x86/include/asm/kdebug.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,20 @@ enum die_val {
2222
DIE_NMIUNKNOWN,
2323
};
2424

25+
enum 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+
2535
extern void die(const char *, struct pt_regs *,long);
2636
extern int __must_check __die(const char *, struct pt_regs *, long);
2737
extern void show_stack_regs(struct pt_regs *regs);
28-
extern void __show_regs(struct pt_regs *regs, int all);
38+
extern void __show_regs(struct pt_regs *regs, enum show_regs_mode);
2939
extern void show_iret_regs(struct pt_regs *regs);
3040
extern unsigned long oops_begin(void);
3141
extern void oops_end(unsigned long, struct pt_regs *, int signr);

arch/x86/kernel/dumpstack.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static void show_regs_if_on_stack(struct stack_info *info, struct pt_regs *regs,
146146
* they can be printed in the right context.
147147
*/
148148
if (!partial && on_stack(info, regs, sizeof(*regs))) {
149-
__show_regs(regs, 0);
149+
__show_regs(regs, SHOW_REGS_SHORT);
150150

151151
} else if (partial && on_stack(info, (void *)regs + IRET_FRAME_OFFSET,
152152
IRET_FRAME_SIZE)) {
@@ -344,7 +344,7 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
344344
oops_exit();
345345

346346
/* Executive summary in case the oops scrolled away */
347-
__show_regs(&exec_summary_regs, true);
347+
__show_regs(&exec_summary_regs, SHOW_REGS_ALL);
348348

349349
if (!signr)
350350
return;
@@ -407,14 +407,9 @@ void die(const char *str, struct pt_regs *regs, long err)
407407

408408
void show_regs(struct pt_regs *regs)
409409
{
410-
bool all = true;
411-
412410
show_regs_print_info(KERN_DEFAULT);
413411

414-
if (IS_ENABLED(CONFIG_X86_32))
415-
all = !user_mode(regs);
416-
417-
__show_regs(regs, all);
412+
__show_regs(regs, user_mode(regs) ? SHOW_REGS_USER : SHOW_REGS_ALL);
418413

419414
/*
420415
* When in-kernel, we also print out the stack at the time of the fault..

arch/x86/kernel/process_32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#include <asm/intel_rdt_sched.h>
6060
#include <asm/proto.h>
6161

62-
void __show_regs(struct pt_regs *regs, int all)
62+
void __show_regs(struct pt_regs *regs, enum show_regs_mode mode)
6363
{
6464
unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L;
6565
unsigned long d0, d1, d2, d3, d6, d7;
@@ -85,7 +85,7 @@ void __show_regs(struct pt_regs *regs, int all)
8585
printk(KERN_DEFAULT "DS: %04x ES: %04x FS: %04x GS: %04x SS: %04x EFLAGS: %08lx\n",
8686
(u16)regs->ds, (u16)regs->es, (u16)regs->fs, gs, ss, regs->flags);
8787

88-
if (!all)
88+
if (mode != SHOW_REGS_ALL)
8989
return;
9090

9191
cr0 = read_cr0();

arch/x86/kernel/process_64.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
__visible DEFINE_PER_CPU(unsigned long, rsp_scratch);
6363

6464
/* Prints also some state that isn't saved in the pt_regs */
65-
void __show_regs(struct pt_regs *regs, int all)
65+
void __show_regs(struct pt_regs *regs, enum show_regs_mode mode)
6666
{
6767
unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
6868
unsigned long d0, d1, d2, d3, d6, d7;
@@ -87,9 +87,17 @@ void __show_regs(struct pt_regs *regs, int all)
8787
printk(KERN_DEFAULT "R13: %016lx R14: %016lx R15: %016lx\n",
8888
regs->r13, regs->r14, regs->r15);
8989

90-
if (!all)
90+
if (mode == SHOW_REGS_SHORT)
9191
return;
9292

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+
93101
asm("movl %%ds,%0" : "=r" (ds));
94102
asm("movl %%cs,%0" : "=r" (cs));
95103
asm("movl %%es,%0" : "=r" (es));

0 commit comments

Comments
 (0)