x86/asm/32: Fix regs_get_register() on segment registers
authorAndy Lutomirski <luto@kernel.org>
Wed, 9 Aug 2017 21:39:45 +0000 (14:39 -0700)
committerIngo Molnar <mingo@kernel.org>
Thu, 10 Aug 2017 11:14:58 +0000 (13:14 +0200)
The segment register high words on x86_32 may contain garbage.
Teach regs_get_register() to read them as u16 instead of unsigned
long.

Signed-off-by: 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: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/0b76f6dbe477b7b1a81938fddcc3c483d48f0ff2.1502314765.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/include/asm/ptrace.h

index a29f8287169990d550c1afe7c44b71c8ea939237..91c04c8e67fabcd2d61c5d47da0f4da9ce7efb4c 100644 (file)
@@ -196,6 +196,17 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
        if (offset == offsetof(struct pt_regs, sp) &&
            regs->cs == __KERNEL_CS)
                return kernel_stack_pointer(regs);
+
+       /* The selector fields are 16-bit. */
+       if (offset == offsetof(struct pt_regs, cs) ||
+           offset == offsetof(struct pt_regs, ss) ||
+           offset == offsetof(struct pt_regs, ds) ||
+           offset == offsetof(struct pt_regs, es) ||
+           offset == offsetof(struct pt_regs, fs) ||
+           offset == offsetof(struct pt_regs, gs)) {
+               return *(u16 *)((unsigned long)regs + offset);
+
+       }
 #endif
        return *(unsigned long *)((unsigned long)regs + offset);
 }