Skip to content

Commit

Permalink
x86/srso: Fix return thunks in generated code
Browse files Browse the repository at this point in the history
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 <jpoimboe@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
  • Loading branch information
Josh Poimboeuf authored and Borislav Petkov (AMD) committed Jul 29, 2023
1 parent d893832 commit 238ec85
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 1 addition & 3 deletions arch/x86/kernel/alternative.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,7 @@ static int patch_return(void *addr, struct insn *insn, u8 *bytes)
int i = 0;

/* Patch the custom return thunks... */
if (cpu_feature_enabled(X86_FEATURE_RETHUNK) ||
cpu_feature_enabled(X86_FEATURE_SRSO) ||
cpu_feature_enabled(X86_FEATURE_SRSO_ALIAS)) {
if (cpu_feature_enabled(X86_FEATURE_RETHUNK)) {
i = JMP32_INSN_SIZE;
__text_gen_insn(bytes, JMP32_INSN_OPCODE, addr, x86_return_thunk, i);
} else {
Expand Down
6 changes: 6 additions & 0 deletions arch/x86/kernel/cpu/bugs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2297,6 +2297,12 @@ static void __init srso_select_mitigation(void)

case SRSO_CMD_SAFE_RET:
if (IS_ENABLED(CONFIG_CPU_SRSO)) {
/*
* Enable the return thunk for generated code
* like ftrace, static_call, etc.
*/
setup_force_cpu_cap(X86_FEATURE_RETHUNK);

if (boot_cpu_data.x86 == 0x19)
setup_force_cpu_cap(X86_FEATURE_SRSO_ALIAS);
else
Expand Down

0 comments on commit 238ec85

Please sign in to comment.