1 From 3ac6d8c787b835b997eb23e43e09aa0895ef7d58 Mon Sep 17 00:00:00 2001
2 From: Dan Williams <dan.j.williams@intel.com>
3 Date: Mon, 5 Feb 2018 17:18:11 -0800
4 Subject: x86/entry/64: Clear registers for exceptions/interrupts, to reduce speculation attack surface
6 From: Dan Williams <dan.j.williams@intel.com>
8 commit 3ac6d8c787b835b997eb23e43e09aa0895ef7d58 upstream.
10 Clear the 'extra' registers on entering the 64-bit kernel for exceptions
11 and interrupts. The common registers are not cleared since they are
12 likely clobbered well before they can be exploited in a speculative
15 Originally-From: Andi Kleen <ak@linux.intel.com>
16 Signed-off-by: Dan Williams <dan.j.williams@intel.com>
17 Cc: <stable@vger.kernel.org>
18 Cc: Andy Lutomirski <luto@kernel.org>
19 Cc: Borislav Petkov <bp@alien8.de>
20 Cc: Brian Gerst <brgerst@gmail.com>
21 Cc: Denys Vlasenko <dvlasenk@redhat.com>
22 Cc: H. Peter Anvin <hpa@zytor.com>
23 Cc: Josh Poimboeuf <jpoimboe@redhat.com>
24 Cc: Linus Torvalds <torvalds@linux-foundation.org>
25 Cc: Peter Zijlstra <peterz@infradead.org>
26 Cc: Thomas Gleixner <tglx@linutronix.de>
27 Link: http://lkml.kernel.org/r/151787989146.7847.15749181712358213254.stgit@dwillia2-desk3.amr.corp.intel.com
28 [ Made small improvements to the changelog and the code comments. ]
29 Signed-off-by: Ingo Molnar <mingo@kernel.org>
30 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33 arch/x86/entry/calling.h | 19 +++++++++++++++++++
34 arch/x86/entry/entry_64.S | 6 +++++-
35 2 files changed, 24 insertions(+), 1 deletion(-)
37 --- a/arch/x86/entry/calling.h
38 +++ b/arch/x86/entry/calling.h
39 @@ -147,6 +147,25 @@ For 32-bit we have the following convent
40 UNWIND_HINT_REGS offset=\offset
44 + * Sanitize registers of values that a speculation attack
45 + * might otherwise want to exploit. The lower registers are
46 + * likely clobbered well before they could be put to use in
47 + * a speculative execution gadget:
49 + .macro CLEAR_REGS_NOSPEC
65 --- a/arch/x86/entry/entry_64.S
66 +++ b/arch/x86/entry/entry_64.S
67 @@ -575,6 +575,7 @@ END(irq_entries_start)
68 ALLOC_PT_GPREGS_ON_STACK
75 @@ -1133,6 +1134,7 @@ ENTRY(xen_failsafe_callback)
76 ALLOC_PT_GPREGS_ON_STACK
82 END(xen_failsafe_callback)
83 @@ -1178,6 +1180,7 @@ ENTRY(paranoid_entry)
88 ENCODE_FRAME_POINTER 8
90 movl $MSR_GS_BASE, %ecx
91 @@ -1230,8 +1233,8 @@ ENTRY(error_entry)
96 ENCODE_FRAME_POINTER 8
99 jz .Lerror_kernelspace
101 @@ -1428,6 +1431,7 @@ ENTRY(nmi)
102 pushq %r14 /* pt_regs->r14 */
103 pushq %r15 /* pt_regs->r15 */