Skip to content

Commit dbbe2ad

Browse files
asteinhaKAGA-KOKO
authored andcommitted
x86/speculation: Prevent rogue cross-process SSBD shutdown
On context switch the change of TIF_SSBD and TIF_SPEC_IB are evaluated to adjust the mitigations accordingly. This is optimized to avoid the expensive MSR write if not needed. This optimization is buggy and allows an attacker to shutdown the SSBD protection of a victim process. The update logic reads the cached base value for the speculation control MSR which has neither the SSBD nor the STIBP bit set. It then OR's the SSBD bit only when TIF_SSBD is different and requests the MSR update. That means if TIF_SSBD of the previous and next task are the same, then the base value is not updated, even if TIF_SSBD is set. The MSR write is not requested. Subsequently if the TIF_STIBP bit differs then the STIBP bit is updated in the base value and the MSR is written with a wrong SSBD value. This was introduced when the per task/process conditional STIPB switching was added on top of the existing SSBD switching. It is exploitable if the attacker creates a process which enforces SSBD and has the contrary value of STIBP than the victim process (i.e. if the victim process enforces STIBP, the attacker process must not enforce it; if the victim process does not enforce STIBP, the attacker process must enforce it) and schedule it on the same core as the victim process. If the victim runs after the attacker the victim becomes vulnerable to Spectre V4. To fix this, update the MSR value independent of the TIF_SSBD difference and dependent on the SSBD mitigation method available. This ensures that a subsequent STIPB initiated MSR write has the correct state of SSBD. [ tglx: Handle X86_FEATURE_VIRT_SSBD & X86_FEATURE_VIRT_SSBD correctly and massaged changelog ] Fixes: 5bfbe3a ("x86/speculation: Prepare for per task indirect branch speculation control") Signed-off-by: Anthony Steinhauser <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected]
1 parent 21998a3 commit dbbe2ad

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

arch/x86/kernel/process.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -545,28 +545,20 @@ static __always_inline void __speculation_ctrl_update(unsigned long tifp,
545545

546546
lockdep_assert_irqs_disabled();
547547

548-
/*
549-
* If TIF_SSBD is different, select the proper mitigation
550-
* method. Note that if SSBD mitigation is disabled or permanentely
551-
* enabled this branch can't be taken because nothing can set
552-
* TIF_SSBD.
553-
*/
554-
if (tif_diff & _TIF_SSBD) {
555-
if (static_cpu_has(X86_FEATURE_VIRT_SSBD)) {
548+
/* Handle change of TIF_SSBD depending on the mitigation method. */
549+
if (static_cpu_has(X86_FEATURE_VIRT_SSBD)) {
550+
if (tif_diff & _TIF_SSBD)
556551
amd_set_ssb_virt_state(tifn);
557-
} else if (static_cpu_has(X86_FEATURE_LS_CFG_SSBD)) {
552+
} else if (static_cpu_has(X86_FEATURE_LS_CFG_SSBD)) {
553+
if (tif_diff & _TIF_SSBD)
558554
amd_set_core_ssb_state(tifn);
559-
} else if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD) ||
560-
static_cpu_has(X86_FEATURE_AMD_SSBD)) {
561-
msr |= ssbd_tif_to_spec_ctrl(tifn);
562-
updmsr = true;
563-
}
555+
} else if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD) ||
556+
static_cpu_has(X86_FEATURE_AMD_SSBD)) {
557+
updmsr |= !!(tif_diff & _TIF_SSBD);
558+
msr |= ssbd_tif_to_spec_ctrl(tifn);
564559
}
565560

566-
/*
567-
* Only evaluate TIF_SPEC_IB if conditional STIBP is enabled,
568-
* otherwise avoid the MSR write.
569-
*/
561+
/* Only evaluate TIF_SPEC_IB if conditional STIBP is enabled. */
570562
if (IS_ENABLED(CONFIG_SMP) &&
571563
static_branch_unlikely(&switch_to_cond_stibp)) {
572564
updmsr |= !!(tif_diff & _TIF_SPEC_IB);

0 commit comments

Comments
 (0)