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>
This commit is contained in:
Josh Poimboeuf
2023-07-28 17:28:43 -05:00
committed by Greg Kroah-Hartman
parent 384d41bea9
commit 4873939c0e
2 changed files with 7 additions and 3 deletions

View File

@@ -678,9 +678,7 @@ static int patch_return(void *addr, struct insn *insn, u8 *bytes)
{ {
int i = 0; int i = 0;
if (cpu_feature_enabled(X86_FEATURE_RETHUNK) || if (cpu_feature_enabled(X86_FEATURE_RETHUNK))
cpu_feature_enabled(X86_FEATURE_SRSO) ||
cpu_feature_enabled(X86_FEATURE_SRSO_ALIAS))
return -1; return -1;
bytes[i++] = RET_INSN_OPCODE; bytes[i++] = RET_INSN_OPCODE;

View File

@@ -2345,6 +2345,12 @@ static void __init srso_select_mitigation(void)
case SRSO_CMD_SAFE_RET: case SRSO_CMD_SAFE_RET:
if (IS_ENABLED(CONFIG_CPU_SRSO)) { 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) if (boot_cpu_data.x86 == 0x19)
setup_force_cpu_cap(X86_FEATURE_SRSO_ALIAS); setup_force_cpu_cap(X86_FEATURE_SRSO_ALIAS);
else else