Skip to content

Commit 238ec85

Browse files
jpoimboebp3tk0v
authored andcommitted
x86/srso: Fix return thunks in generated code
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]>
1 parent d893832 commit 238ec85

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
@@ -707,9 +707,7 @@ static int patch_return(void *addr, struct insn *insn, u8 *bytes)
707707
int i = 0;
708708

709709
/* Patch the custom return thunks... */
710-
if (cpu_feature_enabled(X86_FEATURE_RETHUNK) ||
711-
cpu_feature_enabled(X86_FEATURE_SRSO) ||
712-
cpu_feature_enabled(X86_FEATURE_SRSO_ALIAS)) {
710+
if (cpu_feature_enabled(X86_FEATURE_RETHUNK)) {
713711
i = JMP32_INSN_SIZE;
714712
__text_gen_insn(bytes, JMP32_INSN_OPCODE, addr, x86_return_thunk, i);
715713
} else {

arch/x86/kernel/cpu/bugs.c

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

22982298
case SRSO_CMD_SAFE_RET:
22992299
if (IS_ENABLED(CONFIG_CPU_SRSO)) {
2300+
/*
2301+
* Enable the return thunk for generated code
2302+
* like ftrace, static_call, etc.
2303+
*/
2304+
setup_force_cpu_cap(X86_FEATURE_RETHUNK);
2305+
23002306
if (boot_cpu_data.x86 == 0x19)
23012307
setup_force_cpu_cap(X86_FEATURE_SRSO_ALIAS);
23022308
else

0 commit comments

Comments
 (0)