This is a note to let you know that I've just added the patch titled x86/srso: Fix return thunks in generated code to the 5.10-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: x86-srso-fix-return-thunks-in-generated-code.patch and it can be found in the queue-5.10 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From b07ad30ad7d510c3bc0398a8b4ee98293bca7c77 Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf <jpoimboe@xxxxxxxxxx> Date: Fri, 28 Jul 2023 17:28:43 -0500 Subject: x86/srso: Fix return thunks in generated code From: Josh Poimboeuf <jpoimboe@xxxxxxxxxx> Upstream commit: 238ec850b95a02dcdff3edc86781aa913549282f 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: fb3bd914b3ec ("x86/srso: Add a Speculative RAS Overflow mitigation") Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx> Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- arch/x86/kernel/alternative.c | 4 +--- arch/x86/kernel/cpu/bugs.c | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -678,9 +678,7 @@ static int patch_return(void *addr, stru { int i = 0; - 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)) return -1; bytes[i++] = RET_INSN_OPCODE; --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -2345,6 +2345,12 @@ static void __init srso_select_mitigatio 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 Patches currently in stable-queue which might be from jpoimboe@xxxxxxxxxx are queue-5.10/x86-speculation-add-kconfig-option-for-gds.patch queue-5.10/x86-speculation-add-gather-data-sampling-mitigation.patch queue-5.10/kvm-add-gds_no-support-to-kvm.patch queue-5.10/x86-speculation-add-force-option-to-gds-mitigation.patch queue-5.10/x86-srso-fix-return-thunks-in-generated-code.patch