Skip to content

Commit c7f2cd0

Browse files
jpoimboegregkh
authored andcommitted
x86/srso: Fix return thunks in generated code
Upstream commit: 238ec85 Set X86_FEATURE_RETHUNK when enabling the SRSO mitigation so that generated code (e.g., ftrace, static call, eBPF) generates "jmp __x86_return_thunk" instead of RET. [ bp: Add a comment. ] Fixes: fb3bd91 ("x86/srso: Add a Speculative RAS Overflow mitigation") Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c9ae63d commit c7f2cd0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

arch/x86/kernel/alternative.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,7 @@ static int patch_return(void *addr, struct insn *insn, u8 *bytes)
538538
{
539539
int i = 0;
540540

541-
if (cpu_feature_enabled(X86_FEATURE_RETHUNK) ||
542-
cpu_feature_enabled(X86_FEATURE_SRSO) ||
543-
cpu_feature_enabled(X86_FEATURE_SRSO_ALIAS))
541+
if (cpu_feature_enabled(X86_FEATURE_RETHUNK))
544542
return -1;
545543

546544
bytes[i++] = RET_INSN_OPCODE;

arch/x86/kernel/cpu/bugs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,6 +2415,12 @@ static void __init srso_select_mitigation(void)
24152415

24162416
case SRSO_CMD_SAFE_RET:
24172417
if (IS_ENABLED(CONFIG_CPU_SRSO)) {
2418+
/*
2419+
* Enable the return thunk for generated code
2420+
* like ftrace, static_call, etc.
2421+
*/
2422+
setup_force_cpu_cap(X86_FEATURE_RETHUNK);
2423+
24182424
if (boot_cpu_data.x86 == 0x19)
24192425
setup_force_cpu_cap(X86_FEATURE_SRSO_ALIAS);
24202426
else

0 commit comments

Comments
 (0)