Skip to content

Commit 98b5dab

Browse files
dkaplan2bp3tk0v
authored andcommitted
x86/bugs: Clean up SRSO microcode handling
SRSO microcode only exists for Zen3/Zen4 CPUs. For those CPUs, the microcode is required for any mitigation other than Safe-RET to be effective. Safe-RET can still protect user->kernel and guest->host attacks without microcode. Clarify this in the code and ensure that SRSO_MITIGATION_UCODE_NEEDED is selected for any mitigation besides Safe-RET if the required microcode isn't present. Signed-off-by: David Kaplan <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/[email protected]
1 parent ff54ae7 commit 98b5dab

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,8 +2902,6 @@ early_param("spec_rstack_overflow", srso_parse_cmdline);
29022902

29032903
static void __init srso_select_mitigation(void)
29042904
{
2905-
bool has_microcode;
2906-
29072905
if (!boot_cpu_has_bug(X86_BUG_SRSO) || cpu_mitigations_off())
29082906
srso_mitigation = SRSO_MITIGATION_NONE;
29092907

@@ -2913,23 +2911,30 @@ static void __init srso_select_mitigation(void)
29132911
if (srso_mitigation == SRSO_MITIGATION_AUTO)
29142912
srso_mitigation = SRSO_MITIGATION_SAFE_RET;
29152913

2916-
has_microcode = boot_cpu_has(X86_FEATURE_IBPB_BRTYPE);
2917-
if (has_microcode) {
2918-
/*
2919-
* Zen1/2 with SMT off aren't vulnerable after the right
2920-
* IBPB microcode has been applied.
2921-
*/
2922-
if (boot_cpu_data.x86 < 0x19 && !cpu_smt_possible()) {
2923-
srso_mitigation = SRSO_MITIGATION_NOSMT;
2924-
return;
2925-
}
2926-
} else {
2914+
/* Zen1/2 with SMT off aren't vulnerable to SRSO. */
2915+
if (boot_cpu_data.x86 < 0x19 && !cpu_smt_possible()) {
2916+
srso_mitigation = SRSO_MITIGATION_NOSMT;
2917+
return;
2918+
}
2919+
2920+
if (!boot_cpu_has(X86_FEATURE_IBPB_BRTYPE)) {
29272921
pr_warn("IBPB-extending microcode not applied!\n");
29282922
pr_warn(SRSO_NOTICE);
2923+
2924+
/*
2925+
* Safe-RET provides partial mitigation without microcode, but
2926+
* other mitigations require microcode to provide any
2927+
* mitigations.
2928+
*/
2929+
if (srso_mitigation == SRSO_MITIGATION_SAFE_RET)
2930+
srso_mitigation = SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED;
2931+
else
2932+
srso_mitigation = SRSO_MITIGATION_UCODE_NEEDED;
29292933
}
29302934

29312935
switch (srso_mitigation) {
29322936
case SRSO_MITIGATION_SAFE_RET:
2937+
case SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED:
29332938
if (boot_cpu_has(X86_FEATURE_SRSO_USER_KERNEL_NO)) {
29342939
srso_mitigation = SRSO_MITIGATION_IBPB_ON_VMEXIT;
29352940
goto ibpb_on_vmexit;
@@ -2939,9 +2944,6 @@ static void __init srso_select_mitigation(void)
29392944
pr_err("WARNING: kernel not compiled with MITIGATION_SRSO.\n");
29402945
srso_mitigation = SRSO_MITIGATION_NONE;
29412946
}
2942-
2943-
if (!has_microcode)
2944-
srso_mitigation = SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED;
29452947
break;
29462948
ibpb_on_vmexit:
29472949
case SRSO_MITIGATION_IBPB_ON_VMEXIT:
@@ -2956,9 +2958,6 @@ static void __init srso_select_mitigation(void)
29562958
pr_err("WARNING: kernel not compiled with MITIGATION_IBPB_ENTRY.\n");
29572959
srso_mitigation = SRSO_MITIGATION_NONE;
29582960
}
2959-
2960-
if (!has_microcode)
2961-
srso_mitigation = SRSO_MITIGATION_UCODE_NEEDED;
29622961
break;
29632962
default:
29642963
break;

0 commit comments

Comments
 (0)