History

x86/speculation: Fix RSB filling with CONFIG_RETPOLINE=n

If a kernel is built with CONFIG_RETPOLINE=n, but the user still wants to mitigate Spectre v2 using IBRS or eIBRS, the RSB filling will be silently disabled. There's nothing retpoline-specific about RSB buffer filling. Remove the CONFIG_RETPOLINE guards around it.

Josh Poimboeuf committed 4 years ago

Commit b2620fa1 parent d7caac93 files · +0 −6Browse files

Unified · Split

3 files
  1. arch/x86/entry/entry_32.S +0 −2
  2. arch/x86/entry/entry_64.S +0 −2
  3. arch/x86/include/asm/nospec-branch.h +0 −2
arch/x86/entry/entry_32.S+0−2
@@ -698,7 +698,6 @@ SYM_CODE_START(__switch_to_asm) · 697 unmodified lines
698 movl %ebx, PER_CPU_VAR(__stack_chk_guard)698 movl %ebx, PER_CPU_VAR(__stack_chk_guard)
699#endif699#endif
700 700
701#ifdef CONFIG_RETPOLINE
702 /*701 /*
703 * When switching from a shallower to a deeper call stack702 * When switching from a shallower to a deeper call stack
704 * the RSB may either underflow or use entries populated703 * the RSB may either underflow or use entries populated
@@ -707,7 +706,6 @@ SYM_CODE_START(__switch_to_asm) · 2 unmodified lines
707 * speculative execution to prevent attack.706 * speculative execution to prevent attack.
708 */707 */
709 FILL_RETURN_BUFFER %ebx, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_CTXSW708 FILL_RETURN_BUFFER %ebx, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_CTXSW
710#endif
711 709
712 /* Restore flags or the incoming task to restore AC state. */710 /* Restore flags or the incoming task to restore AC state. */
713 popfl711 popfl
arch/x86/entry/entry_64.S+0−2
@@ -255,7 +255,6 @@ SYM_FUNC_START(__switch_to_asm) · 254 unmodified lines
255 movq %rbx, PER_CPU_VAR(fixed_percpu_data) + stack_canary_offset255 movq %rbx, PER_CPU_VAR(fixed_percpu_data) + stack_canary_offset
256#endif256#endif
257 257
258#ifdef CONFIG_RETPOLINE
259 /*258 /*
260 * When switching from a shallower to a deeper call stack259 * When switching from a shallower to a deeper call stack
261 * the RSB may either underflow or use entries populated260 * the RSB may either underflow or use entries populated
@@ -264,7 +263,6 @@ SYM_FUNC_START(__switch_to_asm) · 2 unmodified lines
264 * speculative execution to prevent attack.263 * speculative execution to prevent attack.
265 */264 */
266 FILL_RETURN_BUFFER %r12, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_CTXSW265 FILL_RETURN_BUFFER %r12, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_CTXSW
267#endif
268 266
269 /* restore callee-saved registers */267 /* restore callee-saved registers */
270 popq %r15268 popq %r15
arch/x86/include/asm/nospec-branch.h+0−2
@@ -122,11 +122,9 @@ · 121 unmodified lines
122 * monstrosity above, manually.122 * monstrosity above, manually.
123 */123 */
124.macro FILL_RETURN_BUFFER reg:req nr:req ftr:req124.macro FILL_RETURN_BUFFER reg:req nr:req ftr:req
125#ifdef CONFIG_RETPOLINE
126 ALTERNATIVE "jmp .Lskip_rsb_\@", "", \ftr125 ALTERNATIVE "jmp .Lskip_rsb_\@", "", \ftr
127 __FILL_RETURN_BUFFER(\reg,\nr,%_ASM_SP)126 __FILL_RETURN_BUFFER(\reg,\nr,%_ASM_SP)
128.Lskip_rsb_\@:127.Lskip_rsb_\@:
129#endif
130.endm128.endm
131 129
132/*130/*