Skip to content

Commit 6b21d2f

Browse files
dkaplan2bp3tk0v
authored andcommitted
x86/bugs: Add attack vector controls for TSA
Use attack vector controls to determine which TSA mitigation to use. [ bp: Simplify the condition in the select function for better readability. ] Signed-off-by: David Kaplan <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/[email protected]
1 parent 02c7d5b commit 6b21d2f

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,28 +1657,43 @@ early_param("tsa", tsa_parse_cmdline);
16571657

16581658
static void __init tsa_select_mitigation(void)
16591659
{
1660-
if (cpu_mitigations_off() || !boot_cpu_has_bug(X86_BUG_TSA)) {
1660+
if (!boot_cpu_has_bug(X86_BUG_TSA)) {
16611661
tsa_mitigation = TSA_MITIGATION_NONE;
16621662
return;
16631663
}
16641664

1665+
if (tsa_mitigation == TSA_MITIGATION_AUTO) {
1666+
bool vm = false, uk = false;
1667+
1668+
tsa_mitigation = TSA_MITIGATION_NONE;
1669+
1670+
if (cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL) ||
1671+
cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER)) {
1672+
tsa_mitigation = TSA_MITIGATION_USER_KERNEL;
1673+
uk = true;
1674+
}
1675+
1676+
if (cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST) ||
1677+
cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_GUEST)) {
1678+
tsa_mitigation = TSA_MITIGATION_VM;
1679+
vm = true;
1680+
}
1681+
1682+
if (uk && vm)
1683+
tsa_mitigation = TSA_MITIGATION_FULL;
1684+
}
1685+
16651686
if (tsa_mitigation == TSA_MITIGATION_NONE)
16661687
return;
16671688

1668-
if (!boot_cpu_has(X86_FEATURE_VERW_CLEAR)) {
1689+
if (!boot_cpu_has(X86_FEATURE_VERW_CLEAR))
16691690
tsa_mitigation = TSA_MITIGATION_UCODE_NEEDED;
1670-
goto out;
1671-
}
1672-
1673-
if (tsa_mitigation == TSA_MITIGATION_AUTO)
1674-
tsa_mitigation = TSA_MITIGATION_FULL;
16751691

16761692
/*
16771693
* No need to set verw_clear_cpu_buf_mitigation_selected - it
16781694
* doesn't fit all cases here and it is not needed because this
16791695
* is the only VERW-based mitigation on AMD.
16801696
*/
1681-
out:
16821697
pr_info("%s\n", tsa_strings[tsa_mitigation]);
16831698
}
16841699

0 commit comments

Comments
 (0)