Skip to content

Commit 3f01dae

Browse files
Dominik BrodowskiIngo Molnar
authored andcommitted
x86/entry/64: Introduce the PUSH_AND_CLEAN_REGS macro
Those instances where ALLOC_PT_GPREGS_ON_STACK is called just before SAVE_AND_CLEAR_REGS can trivially be replaced by PUSH_AND_CLEAN_REGS. This macro uses PUSH instead of MOV and should therefore be faster, at least on newer CPUs. Suggested-by: Linus Torvalds <[email protected]> Signed-off-by: Dominik Brodowski <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent f7bafa2 commit 3f01dae

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

arch/x86/entry/calling.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,42 @@ For 32-bit we have the following conventions - kernel is built with
137137
UNWIND_HINT_REGS offset=\offset
138138
.endm
139139

140+
.macro PUSH_AND_CLEAR_REGS
141+
/*
142+
* Push registers and sanitize registers of values that a
143+
* speculation attack might otherwise want to exploit. The
144+
* lower registers are likely clobbered well before they
145+
* could be put to use in a speculative execution gadget.
146+
* Interleave XOR with PUSH for better uop scheduling:
147+
*/
148+
pushq %rdi /* pt_regs->di */
149+
pushq %rsi /* pt_regs->si */
150+
pushq %rdx /* pt_regs->dx */
151+
pushq %rcx /* pt_regs->cx */
152+
pushq %rax /* pt_regs->ax */
153+
pushq %r8 /* pt_regs->r8 */
154+
xorq %r8, %r8 /* nospec r8 */
155+
pushq %r9 /* pt_regs->r9 */
156+
xorq %r9, %r9 /* nospec r9 */
157+
pushq %r10 /* pt_regs->r10 */
158+
xorq %r10, %r10 /* nospec r10 */
159+
pushq %r11 /* pt_regs->r11 */
160+
xorq %r11, %r11 /* nospec r11*/
161+
pushq %rbx /* pt_regs->rbx */
162+
xorl %ebx, %ebx /* nospec rbx*/
163+
pushq %rbp /* pt_regs->rbp */
164+
xorl %ebp, %ebp /* nospec rbp*/
165+
pushq %r12 /* pt_regs->r12 */
166+
xorq %r12, %r12 /* nospec r12*/
167+
pushq %r13 /* pt_regs->r13 */
168+
xorq %r13, %r13 /* nospec r13*/
169+
pushq %r14 /* pt_regs->r14 */
170+
xorq %r14, %r14 /* nospec r14*/
171+
pushq %r15 /* pt_regs->r15 */
172+
xorq %r15, %r15 /* nospec r15*/
173+
UNWIND_HINT_REGS
174+
.endm
175+
140176
.macro POP_REGS pop_rdi=1 skip_r11rcx=0
141177
popq %r15
142178
popq %r14

arch/x86/entry/entry_64.S

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,7 @@ END(irq_entries_start)
564564
call switch_to_thread_stack
565565
1:
566566

567-
ALLOC_PT_GPREGS_ON_STACK
568-
SAVE_AND_CLEAR_REGS
567+
PUSH_AND_CLEAR_REGS
569568
ENCODE_FRAME_POINTER
570569

571570
testb $3, CS(%rsp)
@@ -1112,8 +1111,7 @@ ENTRY(xen_failsafe_callback)
11121111
addq $0x30, %rsp
11131112
UNWIND_HINT_IRET_REGS
11141113
pushq $-1 /* orig_ax = -1 => not a system call */
1115-
ALLOC_PT_GPREGS_ON_STACK
1116-
SAVE_AND_CLEAR_REGS
1114+
PUSH_AND_CLEAR_REGS
11171115
ENCODE_FRAME_POINTER
11181116
jmp error_exit
11191117
END(xen_failsafe_callback)

0 commit comments

Comments
 (0)