SRSO fixes
Subsystems (2)
cover SRSO fixes
Minor clean-up/fixes for SRSO mitigation handling.
David Kaplan (3):
x86/bugs: Add SRSO_MITIGATION_NOSMT
x86/bugs: Use IBPB for retbleed if used by SRSO
x86/bugs: Clean up SRSO ucode handling
arch/x86/kernel/cpu/bugs.c | 78 +++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 39 deletions(-)
base-commit: 49151ac6671fe0372261054daf5e4da3567b8271
Signature · 1 line
2.34.1
PATCH 1/3 x86/bugs: Add SRSO_MITIGATION_NOSMT
Zen1 and Zen2 CPUs with SMT disabled are not vulnerable to SRSO. Instead of overloading the X86_FEATURE_SRSO_NO bit to indicate this, define a separate mitigation to make the code cleaner.
--- arch/x86/kernel/cpu/bugs.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/bugs.c +4 -7
@@ -2851,6 +2851,7 @@ enum srso_mitigation {SRSO_MITIGATION_UCODE_NEEDED ,SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED ,SRSO_MITIGATION_MICROCODE , +SRSO_MITIGATION_NOSMT ,SRSO_MITIGATION_SAFE_RET ,SRSO_MITIGATION_IBPB , SRSO_MITIGATION_IBPB_ON_VMEXIT,
@@ -2862,6 +2863,7 @@ static const char * const srso_strings[] = { [SRSO_MITIGATION_UCODE_NEEDED] = "Vulnerable: No microcode", [SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED] = "Vulnerable: Safe RET, no microcode", [SRSO_MITIGATION_MICROCODE] = "Vulnerable: Microcode, no safe RET", + [SRSO_MITIGATION_NOSMT] = "Mitigation: SMT disabled", [SRSO_MITIGATION_SAFE_RET] = "Mitigation: Safe RET", [SRSO_MITIGATION_IBPB] = "Mitigation: IBPB", [SRSO_MITIGATION_IBPB_ON_VMEXIT] = "Mitigation: IBPB on VMEXIT only",
@@ -2914,8 +2916,7 @@ static void __init srso_select_mitigation(void)* IBPB microcode has been applied. */ if (boot_cpu_data.x86 <0x19 && !cpu_smt_possible ()) { -setup_force_cpu_cap (X86_FEATURE_SRSO_NO ); - srso_mitigation =SRSO_MITIGATION_NONE ; + srso_mitigation =SRSO_MITIGATION_NOSMT ;return ; } }else {
@@ -2968,8 +2969,7 @@ static void __init srso_update_mitigation(void) srso_mitigation =SRSO_MITIGATION_IBPB ;if (boot_cpu_has_bug (X86_BUG_SRSO ) && - !cpu_mitigations_off () && - !boot_cpu_has (X86_FEATURE_SRSO_NO )) + !cpu_mitigations_off ())pr_info ("%s\n" , srso_strings[srso_mitigation]); }
@@ -3265,9 +3265,6 @@ static ssize_t retbleed_show_state(char *buf)static ssize_t srso_show_state (char *buf) { -if (boot_cpu_has (X86_FEATURE_SRSO_NO )) -return sysfs_emit (buf,"Mitigation: SMT disabled\n" ); -return sysfs_emit (buf,"%s\n" , srso_strings[srso_mitigation]); }
Signature · 1 line
2.34.1
[tip: x86/bugs] x86/bugs: Add SRSO_MITIGATION_NOSMT
The following commit has been merged into the x86/bugs branch of tip:
The following commit has been merged into the x86/bugs branch of tip:
Commit-ID: 1fd5eb02867ac7db9144bd44c8edfad0189c8e57 Gitweb: https://git.kernel.org/tip/1fd5eb02867ac7db9144bd44c8edfad0189c8e57 Author: David Kaplan <[email protected]> AuthorDate: Wed, 25 Jun 2025 10:58:03 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Thu, 26 Jun 2025 10:56:39 +02:00
x86/bugs: Add SRSO_MITIGATION_NOSMT
AMD Zen1 and Zen2 CPUs with SMT disabled are not vulnerable to SRSO.
Instead of overloading the X86_FEATURE_SRSO_NO bit to indicate this, define a separate mitigation to make the code cleaner.
--- arch/x86/kernel/cpu/bugs.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/bugs.c +4 -7
@@ -2851,6 +2851,7 @@ enum srso_mitigation {SRSO_MITIGATION_UCODE_NEEDED ,SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED ,SRSO_MITIGATION_MICROCODE , +SRSO_MITIGATION_NOSMT ,SRSO_MITIGATION_SAFE_RET ,SRSO_MITIGATION_IBPB , SRSO_MITIGATION_IBPB_ON_VMEXIT,
@@ -2862,6 +2863,7 @@ static const char * const srso_strings[] = { [SRSO_MITIGATION_UCODE_NEEDED] = "Vulnerable: No microcode", [SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED] = "Vulnerable: Safe RET, no microcode", [SRSO_MITIGATION_MICROCODE] = "Vulnerable: Microcode, no safe RET", + [SRSO_MITIGATION_NOSMT] = "Mitigation: SMT disabled", [SRSO_MITIGATION_SAFE_RET] = "Mitigation: Safe RET", [SRSO_MITIGATION_IBPB] = "Mitigation: IBPB", [SRSO_MITIGATION_IBPB_ON_VMEXIT] = "Mitigation: IBPB on VMEXIT only",
@@ -2914,8 +2916,7 @@ static void __init srso_select_mitigation(void)* IBPB microcode has been applied. */ if (boot_cpu_data.x86 <0x19 && !cpu_smt_possible ()) { -setup_force_cpu_cap (X86_FEATURE_SRSO_NO ); - srso_mitigation =SRSO_MITIGATION_NONE ; + srso_mitigation =SRSO_MITIGATION_NOSMT ;return ; } }else {
@@ -2968,8 +2969,7 @@ static void __init srso_update_mitigation(void) srso_mitigation =SRSO_MITIGATION_IBPB ;if (boot_cpu_has_bug (X86_BUG_SRSO ) && - !cpu_mitigations_off () && - !boot_cpu_has (X86_FEATURE_SRSO_NO )) + !cpu_mitigations_off ())pr_info ("%s\n" , srso_strings[srso_mitigation]); }
@@ -3265,9 +3265,6 @@ static ssize_t retbleed_show_state(char *buf)static ssize_t srso_show_state (char *buf) { -if (boot_cpu_has (X86_FEATURE_SRSO_NO )) -return sysfs_emit (buf,"Mitigation: SMT disabled\n" ); -return sysfs_emit (buf,"%s\n" , srso_strings[srso_mitigation]); }
PATCH 2/3 x86/bugs: Use IBPB for retbleed if used by SRSO
In reply to David KaplanIf spec_rstack_overflow=ibpb then this mitigates retbleed as well. This is relevant for Zen1 and Zen2 CPUs which are vulnerable to both bugs.
--- arch/x86/kernel/cpu/bugs.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
arch/x86/kernel/cpu/bugs.c +19 -15
@@ -1171,6 +1171,21 @@ static enum retbleed_mitigation retbleed_mitigation __ro_after_init =static int __ro_after_init retbleed_nosmt = false; +enum srso_mitigation { +SRSO_MITIGATION_NONE , +SRSO_MITIGATION_AUTO , +SRSO_MITIGATION_UCODE_NEEDED , +SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED , +SRSO_MITIGATION_MICROCODE , +SRSO_MITIGATION_NOSMT , +SRSO_MITIGATION_SAFE_RET , +SRSO_MITIGATION_IBPB , +SRSO_MITIGATION_IBPB_ON_VMEXIT , +SRSO_MITIGATION_BP_SPEC_REDUCE , +}; + +static enum srso_mitigation srso_mitigation__ro_after_init =SRSO_MITIGATION_AUTO ; +static int __init retbleed_parse_cmdline (char *str) {if (!str)
@@ -1280,6 +1295,10 @@ static void __init retbleed_update_mitigation(void)if (its_mitigation ==ITS_MITIGATION_RETPOLINE_STUFF ) retbleed_mitigation =RETBLEED_MITIGATION_STUFF ; +/* If SRSO is using IBPB, that works for retbleed too */ +if (srso_mitigation ==SRSO_MITIGATION_IBPB ) + retbleed_mitigation =RETBLEED_MITIGATION_IBPB ; +if (retbleed_mitigation ==RETBLEED_MITIGATION_STUFF && !cdt_possible (spectre_v2_enabled)) {pr_err ("WARNING: retbleed=stuff depends on retpoline\n" );
@@ -2845,19 +2864,6 @@ early_param("l1tf", l1tf_cmdline);#undef pr_fmt#define pr_fmt (fmt) "Speculative Return Stack Overflow: " fmt -enum srso_mitigation { -SRSO_MITIGATION_NONE , -SRSO_MITIGATION_AUTO , -SRSO_MITIGATION_UCODE_NEEDED , -SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED , -SRSO_MITIGATION_MICROCODE , -SRSO_MITIGATION_NOSMT , -SRSO_MITIGATION_SAFE_RET , -SRSO_MITIGATION_IBPB , -SRSO_MITIGATION_IBPB_ON_VMEXIT , -SRSO_MITIGATION_BP_SPEC_REDUCE , -}; -static const char *const srso_strings[] = { [SRSO_MITIGATION_NONE ] ="Vulnerable" , [SRSO_MITIGATION_UCODE_NEEDED ] ="Vulnerable: No microcode" ,
@@ -2870,8 +2876,6 @@ static const char * const srso_strings[] = { [SRSO_MITIGATION_BP_SPEC_REDUCE] = "Mitigation: Reduced Speculation" }; -static enum srso_mitigation srso_mitigation__ro_after_init =SRSO_MITIGATION_AUTO ; -static int __init srso_parse_cmdline (char *str) {if (!str)
Signature · 1 line
2.34.1
[tip: x86/bugs] x86/bugs: Use IBPB for retbleed if used by SRSO
The following commit has been merged into the x86/bugs branch of tip:
The following commit has been merged into the x86/bugs branch of tip:
Commit-ID: ff54ae7314962699749869a3475da7a702ae991a Gitweb: https://git.kernel.org/tip/ff54ae7314962699749869a3475da7a702ae991a Author: David Kaplan <[email protected]> AuthorDate: Wed, 25 Jun 2025 10:58:04 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Thu, 26 Jun 2025 10:56:39 +02:00
x86/bugs: Use IBPB for retbleed if used by SRSO
If spec_rstack_overflow=ibpb then this mitigates retbleed as well. This is relevant for AMD Zen1 and Zen2 CPUs which are vulnerable to both bugs.
--- arch/x86/kernel/cpu/bugs.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
arch/x86/kernel/cpu/bugs.c +19 -15
@@ -1171,6 +1171,21 @@ static enum retbleed_mitigation retbleed_mitigation __ro_after_init =static int __ro_after_init retbleed_nosmt = false; +enum srso_mitigation { +SRSO_MITIGATION_NONE , +SRSO_MITIGATION_AUTO , +SRSO_MITIGATION_UCODE_NEEDED , +SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED , +SRSO_MITIGATION_MICROCODE , +SRSO_MITIGATION_NOSMT , +SRSO_MITIGATION_SAFE_RET , +SRSO_MITIGATION_IBPB , +SRSO_MITIGATION_IBPB_ON_VMEXIT , +SRSO_MITIGATION_BP_SPEC_REDUCE , +}; + +static enum srso_mitigation srso_mitigation__ro_after_init =SRSO_MITIGATION_AUTO ; +static int __init retbleed_parse_cmdline (char *str) {if (!str)
@@ -1280,6 +1295,10 @@ static void __init retbleed_update_mitigation(void)if (its_mitigation ==ITS_MITIGATION_RETPOLINE_STUFF ) retbleed_mitigation =RETBLEED_MITIGATION_STUFF ; +/* If SRSO is using IBPB, that works for retbleed too */ +if (srso_mitigation ==SRSO_MITIGATION_IBPB ) + retbleed_mitigation =RETBLEED_MITIGATION_IBPB ; +if (retbleed_mitigation ==RETBLEED_MITIGATION_STUFF && !cdt_possible (spectre_v2_enabled)) {pr_err ("WARNING: retbleed=stuff depends on retpoline\n" );
@@ -2845,19 +2864,6 @@ early_param("l1tf", l1tf_cmdline);#undef pr_fmt#define pr_fmt (fmt) "Speculative Return Stack Overflow: " fmt -enum srso_mitigation { -SRSO_MITIGATION_NONE , -SRSO_MITIGATION_AUTO , -SRSO_MITIGATION_UCODE_NEEDED , -SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED , -SRSO_MITIGATION_MICROCODE , -SRSO_MITIGATION_NOSMT , -SRSO_MITIGATION_SAFE_RET , -SRSO_MITIGATION_IBPB , -SRSO_MITIGATION_IBPB_ON_VMEXIT , -SRSO_MITIGATION_BP_SPEC_REDUCE , -}; -static const char *const srso_strings[] = { [SRSO_MITIGATION_NONE ] ="Vulnerable" , [SRSO_MITIGATION_UCODE_NEEDED ] ="Vulnerable: No microcode" ,
@@ -2870,8 +2876,6 @@ static const char * const srso_strings[] = { [SRSO_MITIGATION_BP_SPEC_REDUCE] = "Mitigation: Reduced Speculation" }; -static enum srso_mitigation srso_mitigation__ro_after_init =SRSO_MITIGATION_AUTO ; -static int __init srso_parse_cmdline (char *str) {if (!str)
PATCH 3/3 x86/bugs: Clean up SRSO ucode handling
In reply to David KaplanSRSO ucode only exists for Zen3/Zen4 CPUs. For those CPUs, the ucode is required for any mitigation other than Safe-RET to be effective. Safe-RET can still protect user->kernel and guest->host attacks without ucode.
Clarify this in the code and ensure that SRSO_MITIGATION_UCODE_NEEDED is selected for any mitigation besides Safe-RET if the required ucode isn't present.
--- arch/x86/kernel/cpu/bugs.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-)
arch/x86/kernel/cpu/bugs.c +18 -19
@@ -2902,8 +2902,6 @@ early_param("spec_rstack_overflow", srso_parse_cmdline);static void __init srso_select_mitigation (void ) { -bool has_microcode; -if (!boot_cpu_has_bug (X86_BUG_SRSO ) ||cpu_mitigations_off ()) srso_mitigation =SRSO_MITIGATION_NONE ;
@@ -2913,23 +2911,30 @@ static void __init srso_select_mitigation(void)if (srso_mitigation ==SRSO_MITIGATION_AUTO ) srso_mitigation =SRSO_MITIGATION_SAFE_RET ; - has_microcode =boot_cpu_has (X86_FEATURE_IBPB_BRTYPE ); -if (has_microcode) { -/* -* Zen1/2 with SMT off aren't vulnerable after the right -* IBPB microcode has been applied. -*/ -if (boot_cpu_data.x86 <0x19 && !cpu_smt_possible ()) { - srso_mitigation =SRSO_MITIGATION_NOSMT ; -return ; - } - }else { +/* Zen1/2 with SMT off aren't vulnerable to SRSO. */ +if (boot_cpu_data.x86 <0x19 && !cpu_smt_possible ()) { + srso_mitigation =SRSO_MITIGATION_NOSMT ; +return ; + } + +if (!boot_cpu_has (X86_FEATURE_IBPB_BRTYPE )) {pr_warn ("IBPB-extending microcode not applied!\n" );pr_warn (SRSO_NOTICE ); + +/* +* Safe-RET provides partial mitigation without microcode, but +* other mitigations require microcode to provide any +* mitigations. +*/ +if (srso_mitigation ==SRSO_MITIGATION_SAFE_RET ) + srso_mitigation =SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED ; +else + srso_mitigation =SRSO_MITIGATION_UCODE_NEEDED ; }switch (srso_mitigation) {case SRSO_MITIGATION_SAFE_RET : +case SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED :if (boot_cpu_has (X86_FEATURE_SRSO_USER_KERNEL_NO )) { srso_mitigation =SRSO_MITIGATION_IBPB_ON_VMEXIT ; goto ibpb_on_vmexit;
@@ -2939,9 +2944,6 @@ static void __init srso_select_mitigation(void)pr_err ("WARNING: kernel not compiled with MITIGATION_SRSO.\n" ); srso_mitigation =SRSO_MITIGATION_NONE ; } - -if (!has_microcode) - srso_mitigation =SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED ;break ; ibpb_on_vmexit:case SRSO_MITIGATION_IBPB_ON_VMEXIT :
@@ -2956,9 +2958,6 @@ static void __init srso_select_mitigation(void)pr_err ("WARNING: kernel not compiled with MITIGATION_IBPB_ENTRY.\n" ); srso_mitigation =SRSO_MITIGATION_NONE ; } - -if (!has_microcode) - srso_mitigation =SRSO_MITIGATION_UCODE_NEEDED ;break ;default :break ;
Signature · 1 line
2.34.1
[tip: x86/bugs] x86/bugs: Clean up SRSO microcode handling
The following commit has been merged into the x86/bugs branch of tip:
The following commit has been merged into the x86/bugs branch of tip:
Commit-ID: 98b5dab4d22181c931f2bf63c060416badbb49ab Gitweb: https://git.kernel.org/tip/98b5dab4d22181c931f2bf63c060416badbb49ab Author: David Kaplan <[email protected]> AuthorDate: Wed, 25 Jun 2025 10:58:05 -05:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Thu, 26 Jun 2025 13:32:31 +02:00
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.
--- arch/x86/kernel/cpu/bugs.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-)
arch/x86/kernel/cpu/bugs.c +18 -19
@@ -2902,8 +2902,6 @@ early_param("spec_rstack_overflow", srso_parse_cmdline);static void __init srso_select_mitigation (void ) { -bool has_microcode; -if (!boot_cpu_has_bug (X86_BUG_SRSO ) ||cpu_mitigations_off ()) srso_mitigation =SRSO_MITIGATION_NONE ;
@@ -2913,23 +2911,30 @@ static void __init srso_select_mitigation(void)if (srso_mitigation ==SRSO_MITIGATION_AUTO ) srso_mitigation =SRSO_MITIGATION_SAFE_RET ; - has_microcode =boot_cpu_has (X86_FEATURE_IBPB_BRTYPE ); -if (has_microcode) { -/* -* Zen1/2 with SMT off aren't vulnerable after the right -* IBPB microcode has been applied. -*/ -if (boot_cpu_data.x86 <0x19 && !cpu_smt_possible ()) { - srso_mitigation =SRSO_MITIGATION_NOSMT ; -return ; - } - }else { +/* Zen1/2 with SMT off aren't vulnerable to SRSO. */ +if (boot_cpu_data.x86 <0x19 && !cpu_smt_possible ()) { + srso_mitigation =SRSO_MITIGATION_NOSMT ; +return ; + } + +if (!boot_cpu_has (X86_FEATURE_IBPB_BRTYPE )) {pr_warn ("IBPB-extending microcode not applied!\n" );pr_warn (SRSO_NOTICE ); + +/* +* Safe-RET provides partial mitigation without microcode, but +* other mitigations require microcode to provide any +* mitigations. +*/ +if (srso_mitigation ==SRSO_MITIGATION_SAFE_RET ) + srso_mitigation =SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED ; +else + srso_mitigation =SRSO_MITIGATION_UCODE_NEEDED ; }switch (srso_mitigation) {case SRSO_MITIGATION_SAFE_RET : +case SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED :if (boot_cpu_has (X86_FEATURE_SRSO_USER_KERNEL_NO )) { srso_mitigation =SRSO_MITIGATION_IBPB_ON_VMEXIT ; goto ibpb_on_vmexit;
@@ -2939,9 +2944,6 @@ static void __init srso_select_mitigation(void)pr_err ("WARNING: kernel not compiled with MITIGATION_SRSO.\n" ); srso_mitigation =SRSO_MITIGATION_NONE ; } - -if (!has_microcode) - srso_mitigation =SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED ;break ; ibpb_on_vmexit:case SRSO_MITIGATION_IBPB_ON_VMEXIT :
@@ -2956,9 +2958,6 @@ ibpb_on_vmexit:pr_err ("WARNING: kernel not compiled with MITIGATION_IBPB_ENTRY.\n" ); srso_mitigation =SRSO_MITIGATION_NONE ; } - -if (!has_microcode) - srso_mitigation =SRSO_MITIGATION_UCODE_NEEDED ;break ;default :break ;