summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Poimboeuf <jpoimboe@kernel.org>2023-07-28 17:28:43 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-08-08 20:04:52 +0200
commitb155f54a92b0c8fe62eb5b45d062613626428fc5 (patch)
treec87cdc5e3d6288b5cef4f67add893ceded83e076
parentb31eb84b6756825ce935ce0390025b2b09b4ecb4 (diff)
downloadlinux-stable-b155f54a92b0c8fe62eb5b45d062613626428fc5.tar.gz
linux-stable-b155f54a92b0c8fe62eb5b45d062613626428fc5.tar.bz2
linux-stable-b155f54a92b0c8fe62eb5b45d062613626428fc5.zip
x86/srso: Fix return thunks in generated code
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>
-rw-r--r--arch/x86/kernel/alternative.c4
-rw-r--r--arch/x86/kernel/cpu/bugs.c6
2 files changed, 7 insertions, 3 deletions
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index d516781e5756..f615e0cb6d93 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -590,9 +590,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)) {
if (x86_return_thunk == __x86_return_thunk)
return -1;
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 1ba0e1c0650d..9ab38d04f686 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -2444,6 +2444,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