Skip to content

Commit 22b5557

Browse files
djbwgregkh
authored andcommitted
x86/entry/64: Clear extra registers beyond syscall arguments, to reduce speculation attack surface
commit 8e1eb3f upstream. At entry userspace may have (maliciously) populated the extra registers outside the syscall calling convention with arbitrary values that could be useful in a speculative execution (Spectre style) attack. Clear these registers to minimize the kernel's attack surface. Note, this only clears the extra registers and not the unused registers for syscalls less than 6 arguments, since those registers are likely to be clobbered well before their values could be put to use under speculation. Note, Linus found that the XOR instructions can be executed with minimized cost if interleaved with the PUSH instructions, and Ingo's analysis found that R10 and R11 should be included in the register clearing beyond the typical 'extra' syscall calling convention registers. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Reported-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Cc: <stable@vger.kernel.org> Cc: 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: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/151787988577.7847.16733592218894189003.stgit@dwillia2-desk3.amr.corp.intel.com [ Made small improvements to the changelog and the code comments. ] Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 78b1cb3 commit 22b5557

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

arch/x86/entry/entry_64.S

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,26 @@ GLOBAL(entry_SYSCALL_64_after_swapgs)
176176
pushq %r8 /* pt_regs->r8 */
177177
pushq %r9 /* pt_regs->r9 */
178178
pushq %r10 /* pt_regs->r10 */
179+
/*
180+
* Clear extra registers that a speculation attack might
181+
* otherwise want to exploit. Interleave XOR with PUSH
182+
* for better uop scheduling:
183+
*/
184+
xorq %r10, %r10 /* nospec r10 */
179185
pushq %r11 /* pt_regs->r11 */
186+
xorq %r11, %r11 /* nospec r11 */
180187
pushq %rbx /* pt_regs->rbx */
188+
xorl %ebx, %ebx /* nospec rbx */
181189
pushq %rbp /* pt_regs->rbp */
190+
xorl %ebp, %ebp /* nospec rbp */
182191
pushq %r12 /* pt_regs->r12 */
192+
xorq %r12, %r12 /* nospec r12 */
183193
pushq %r13 /* pt_regs->r13 */
194+
xorq %r13, %r13 /* nospec r13 */
184195
pushq %r14 /* pt_regs->r14 */
196+
xorq %r14, %r14 /* nospec r14 */
185197
pushq %r15 /* pt_regs->r15 */
198+
xorq %r15, %r15 /* nospec r15 */
186199

187200
/* IRQs are off. */
188201
movq %rsp, %rdi

0 commit comments

Comments
 (0)