Skip to content

Commit c3ba121

Browse files
Peter Zijlstravijay-suman
authored andcommitted
x86,nospec: Simplify {JMP,CALL}_NOSPEC
commit 09d0953 upstream. 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]> Signed-off-by: Pawan Gupta <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 8595a7453a5f69a0db7077b13f2975b855aeb049) Signed-off-by: Vijayendra Suman <[email protected]>
1 parent 7037c15 commit c3ba121

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
@@ -118,26 +118,38 @@
118118
#endif
119119
.endm
120120

121+
/*
122+
* Equivalent to -mindirect-branch-cs-prefix; emit the 5 byte jmp/call
123+
* to the retpoline thunk with a CS prefix when the register requires
124+
* a RAX prefix byte to encode. Also see apply_retpolines().
125+
*/
126+
.macro __CS_PREFIX reg:req
127+
.irp rs,r8,r9,r10,r11,r12,r13,r14,r15
128+
.ifc \reg,\rs
129+
.byte 0x2e
130+
.endif
131+
.endr
132+
.endm
133+
121134
/*
122135
* JMP_NOSPEC and CALL_NOSPEC macros can be used instead of a simple
123136
* indirect jmp/call which may be susceptible to the Spectre variant 2
124137
* attack.
125138
*/
126139
.macro JMP_NOSPEC reg:req
127140
#ifdef CONFIG_RETPOLINE
128-
ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \
129-
__stringify(jmp __x86_indirect_thunk_\reg), X86_FEATURE_RETPOLINE, \
130-
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), X86_FEATURE_RETPOLINE_LFENCE
141+
__CS_PREFIX \reg
142+
jmp __x86_indirect_thunk_\reg
131143
#else
132144
jmp *%\reg
145+
int3
133146
#endif
134147
.endm
135148

136149
.macro CALL_NOSPEC reg:req
137150
#ifdef CONFIG_RETPOLINE
138-
ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; call *%\reg), \
139-
__stringify(call __x86_indirect_thunk_\reg), X86_FEATURE_RETPOLINE, \
140-
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; call *%\reg), X86_FEATURE_RETPOLINE_LFENCE
151+
__CS_PREFIX \reg
152+
call __x86_indirect_thunk_\reg
141153
#else
142154
call *%\reg
143155
#endif

0 commit comments

Comments
 (0)