Skip to content

Commit 2d31d28

Browse files
dkaplan2bp3tk0v
authored andcommitted
x86/bugs: Define attack vectors relevant for each bug
Add a function which defines which vulnerabilities should be mitigated based on the selected attack vector controls. The selections here are based on the individual characteristics of each vulnerability. Signed-off-by: David Kaplan <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/[email protected]
1 parent 735e592 commit 2d31d28

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,62 @@ static void x86_amd_ssb_disable(void)
332332
#undef pr_fmt
333333
#define pr_fmt(fmt) "MDS: " fmt
334334

335+
/*
336+
* Returns true if vulnerability should be mitigated based on the
337+
* selected attack vector controls.
338+
*
339+
* See Documentation/admin-guide/hw-vuln/attack_vector_controls.rst
340+
*/
341+
static bool __init should_mitigate_vuln(unsigned int bug)
342+
{
343+
switch (bug) {
344+
/*
345+
* The only runtime-selected spectre_v1 mitigations in the kernel are
346+
* related to SWAPGS protection on kernel entry. Therefore, protection
347+
* is only required for the user->kernel attack vector.
348+
*/
349+
case X86_BUG_SPECTRE_V1:
350+
return cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL);
351+
352+
case X86_BUG_SPECTRE_V2:
353+
case X86_BUG_RETBLEED:
354+
case X86_BUG_SRSO:
355+
case X86_BUG_L1TF:
356+
case X86_BUG_ITS:
357+
return cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL) ||
358+
cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST);
359+
360+
case X86_BUG_SPECTRE_V2_USER:
361+
return cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER) ||
362+
cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_GUEST);
363+
364+
/*
365+
* All the vulnerabilities below allow potentially leaking data
366+
* across address spaces. Therefore, mitigation is required for
367+
* any of these 4 attack vectors.
368+
*/
369+
case X86_BUG_MDS:
370+
case X86_BUG_TAA:
371+
case X86_BUG_MMIO_STALE_DATA:
372+
case X86_BUG_RFDS:
373+
case X86_BUG_SRBDS:
374+
return cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL) ||
375+
cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST) ||
376+
cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER) ||
377+
cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_GUEST);
378+
379+
case X86_BUG_GDS:
380+
return cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL) ||
381+
cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST) ||
382+
cpu_attack_vector_mitigated(CPU_MITIGATE_USER_USER) ||
383+
cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_GUEST) ||
384+
(smt_mitigations != SMT_MITIGATIONS_OFF);
385+
default:
386+
WARN(1, "Unknown bug %x\n", bug);
387+
return false;
388+
}
389+
}
390+
335391
/* Default mitigation for MDS-affected CPUs */
336392
static enum mds_mitigations mds_mitigation __ro_after_init =
337393
IS_ENABLED(CONFIG_MITIGATION_MDS) ? MDS_MITIGATION_AUTO : MDS_MITIGATION_OFF;

0 commit comments

Comments
 (0)