x86/fsgsbase/64: Report FSBASE and GSBASE correctly in core dumps
authorAndy Lutomirski <[email protected]>
Tue, 1 Aug 2017 14:11:35 +0000 (07:11 -0700)
committerIngo Molnar <[email protected]>
Thu, 10 Aug 2017 15:15:13 +0000 (17:15 +0200)
In ELF_COPY_CORE_REGS, we're copying from the current task, so
accessing thread.fsbase and thread.gsbase makes no sense.  Just read
the values from the CPU registers.

In practice, the old code would have been correct most of the time
simply because thread.fsbase and thread.gsbase usually matched the
CPU registers.

Signed-off-by: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[email protected]>
Cc: Chang Seok <[email protected]>
Cc: Denys Vlasenko <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Josh Poimboeuf <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: [email protected]
Signed-off-by: Ingo Molnar <[email protected]>
arch/x86/include/asm/elf.h

index a62a12c472333280206c10e129bdf3efae40494a..da3250ea864a2efa1cfa940cbf5bf9a2b7731336 100644 (file)
@@ -204,6 +204,7 @@ void set_personality_ia32(bool);
 
 #define ELF_CORE_COPY_REGS(pr_reg, regs)                       \
 do {                                                           \
+       unsigned long base;                                     \
        unsigned v;                                             \
        (pr_reg)[0] = (regs)->r15;                              \
        (pr_reg)[1] = (regs)->r14;                              \
@@ -226,8 +227,8 @@ do {                                                                \
        (pr_reg)[18] = (regs)->flags;                           \
        (pr_reg)[19] = (regs)->sp;                              \
        (pr_reg)[20] = (regs)->ss;                              \
-       (pr_reg)[21] = current->thread.fsbase;                  \
-       (pr_reg)[22] = current->thread.gsbase;                  \
+       rdmsrl(MSR_FS_BASE, base); (pr_reg)[21] = base;         \
+       rdmsrl(MSR_KERNEL_GS_BASE, base); (pr_reg)[22] = base;  \
        asm("movl %%ds,%0" : "=r" (v)); (pr_reg)[23] = v;       \
        asm("movl %%es,%0" : "=r" (v)); (pr_reg)[24] = v;       \
        asm("movl %%fs,%0" : "=r" (v)); (pr_reg)[25] = v;       \