Skip to content

Commit 09d0953

Browse files
author
Peter Zijlstra
committed
x86,nospec: Simplify {JMP,CALL}_NOSPEC
Have {JMP,CALL}_NOSPEC generate the same code GCC does for indirect calls and rely on the objtool retpoline patching infrastructure. There's no reason these should be alternatives while the vast bulk of compiler generated retpolines are not. Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
1 parent ff69927 commit 09d0953

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

arch/x86/include/asm/nospec-branch.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,38 @@
9393
#endif
9494
.endm
9595

96+
/*
97+
* Equivalent to -mindirect-branch-cs-prefix; emit the 5 byte jmp/call
98+
* to the retpoline thunk with a CS prefix when the register requires
99+
* a RAX prefix byte to encode. Also see apply_retpolines().
100+
*/
101+
.macro __CS_PREFIX reg:req
102+
.irp rs,r8,r9,r10,r11,r12,r13,r14,r15
103+
.ifc \reg,\rs
104+
.byte 0x2e
105+
.endif
106+
.endr
107+
.endm
108+
96109
/*
97110
* JMP_NOSPEC and CALL_NOSPEC macros can be used instead of a simple
98111
* indirect jmp/call which may be susceptible to the Spectre variant 2
99112
* attack.
100113
*/
101114
.macro JMP_NOSPEC reg:req
102115
#ifdef CONFIG_RETPOLINE
103-
ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \
104-
__stringify(jmp __x86_indirect_thunk_\reg), X86_FEATURE_RETPOLINE, \
105-
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), X86_FEATURE_RETPOLINE_LFENCE
116+
__CS_PREFIX \reg
117+
jmp __x86_indirect_thunk_\reg
106118
#else
107119
jmp *%\reg
120+
int3
108121
#endif
109122
.endm
110123

111124
.macro CALL_NOSPEC reg:req
112125
#ifdef CONFIG_RETPOLINE
113-
ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; call *%\reg), \
114-
__stringify(call __x86_indirect_thunk_\reg), X86_FEATURE_RETPOLINE, \
115-
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; call *%\reg), X86_FEATURE_RETPOLINE_LFENCE
126+
__CS_PREFIX \reg
127+
call __x86_indirect_thunk_\reg
116128
#else
117129
call *%\reg
118130
#endif

0 commit comments

Comments
 (0)