]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
x86/srso: Fix return thunks in generated code
authorJosh Poimboeuf <jpoimboe@kernel.org>
Fri, 28 Jul 2023 22:28:43 +0000 (17:28 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 8 Aug 2023 17:58:34 +0000 (19:58 +0200)
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@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kernel/alternative.c
arch/x86/kernel/cpu/bugs.c

index 2c7d97c4579652a35118613f4b574aadf77b0439..43dd7f281a216514e551bb304459064ce4341dca 100644 (file)
@@ -523,9 +523,7 @@ static int patch_return(void *addr, struct insn *insn, u8 *bytes)
 {
        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;
index 3f490db41a39c4ae2412f5142c76bc023b5cb88c..c5d9a81234d9fb6ddc8a5e43e54ee526d8672de3 100644 (file)
@@ -2415,6 +2415,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