Skip to content

Commit 92fc27c

Browse files
Daniel Sneddongregkh
authored andcommitted
x86/speculation: Add force option to GDS mitigation
commit 553a5c0 upstream The Gather Data Sampling (GDS) vulnerability allows malicious software to infer stale data previously stored in vector registers. This may include sensitive data such as cryptographic keys. GDS is mitigated in microcode, and systems with up-to-date microcode are protected by default. However, any affected system that is running with older microcode will still be vulnerable to GDS attacks. Since the gather instructions used by the attacker are part of the AVX2 and AVX512 extensions, disabling these extensions prevents gather instructions from being executed, thereby mitigating the system from GDS. Disabling AVX2 is sufficient, but we don't have the granularity to do this. The XCR0[2] disables AVX, with no option to just disable AVX2. Add a kernel parameter gather_data_sampling=force that will enable the microcode mitigation if available, otherwise it will disable AVX on affected systems. This option will be ignored if cmdline mitigations=off. This is a *big* hammer. It is known to break buggy userspace that uses incomplete, buggy AVX enumeration. Unfortunately, such userspace does exist in the wild: https://www.mail-archive.com/[email protected]/msg33046.html [ dhansen: add some more ominous warnings about disabling AVX ] Signed-off-by: Daniel Sneddon <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Signed-off-by: Daniel Sneddon <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c66ebe0 commit 92fc27c

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

Documentation/admin-guide/hw-vuln/gather_data_sampling.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,21 @@ bits:
6060
================================ === ============================
6161

6262
GDS can also be mitigated on systems that don't have updated microcode by
63-
disabling AVX. This can be done by setting "clearcpuid=avx" on the kernel
64-
command-line.
63+
disabling AVX. This can be done by setting gather_data_sampling="force" or
64+
"clearcpuid=avx" on the kernel command-line.
65+
66+
If used, these options will disable AVX use by turning on XSAVE YMM support.
67+
However, the processor will still enumerate AVX support. Userspace that
68+
does not follow proper AVX enumeration to check both AVX *and* XSAVE YMM
69+
support will break.
6570

6671
Mitigation control on the kernel command line
6772
---------------------------------------------
6873
The mitigation can be disabled by setting "gather_data_sampling=off" or
69-
"mitigations=off" on the kernel command line. Not specifying either will
70-
default to the mitigation being enabled.
74+
"mitigations=off" on the kernel command line. Not specifying either will default
75+
to the mitigation being enabled. Specifying "gather_data_sampling=force" will
76+
use the microcode mitigation when available or disable AVX on affected systems
77+
where the microcode hasn't been updated to include the mitigation.
7178

7279
GDS System Information
7380
------------------------
@@ -83,6 +90,9 @@ The possible values contained in this file are:
8390
Vulnerable Processor vulnerable and mitigation disabled.
8491
Vulnerable: No microcode Processor vulnerable and microcode is missing
8592
mitigation.
93+
Mitigation: AVX disabled,
94+
no microcode Processor is vulnerable and microcode is missing
95+
mitigation. AVX disabled as mitigation.
8696
Mitigation: Microcode Processor is vulnerable and mitigation is in
8797
effect.
8898
Mitigation: Microcode (locked) Processor is vulnerable and mitigation is in

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,13 @@
16031603

16041604
This issue is mitigated by default in updated microcode.
16051605
The mitigation may have a performance impact but can be
1606-
disabled.
1606+
disabled. On systems without the microcode mitigation
1607+
disabling AVX serves as a mitigation.
1608+
1609+
force: Disable AVX to mitigate systems without
1610+
microcode mitigation. No effect if the microcode
1611+
mitigation is present. Known to cause crashes in
1612+
userspace with buggy AVX enumeration.
16071613

16081614
off: Disable GDS mitigation.
16091615

arch/x86/kernel/cpu/bugs.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ early_param("l1d_flush", l1d_flush_parse_cmdline);
652652
enum gds_mitigations {
653653
GDS_MITIGATION_OFF,
654654
GDS_MITIGATION_UCODE_NEEDED,
655+
GDS_MITIGATION_FORCE,
655656
GDS_MITIGATION_FULL,
656657
GDS_MITIGATION_FULL_LOCKED,
657658
GDS_MITIGATION_HYPERVISOR,
@@ -662,6 +663,7 @@ static enum gds_mitigations gds_mitigation __ro_after_init = GDS_MITIGATION_FULL
662663
static const char * const gds_strings[] = {
663664
[GDS_MITIGATION_OFF] = "Vulnerable",
664665
[GDS_MITIGATION_UCODE_NEEDED] = "Vulnerable: No microcode",
666+
[GDS_MITIGATION_FORCE] = "Mitigation: AVX disabled, no microcode",
665667
[GDS_MITIGATION_FULL] = "Mitigation: Microcode",
666668
[GDS_MITIGATION_FULL_LOCKED] = "Mitigation: Microcode (locked)",
667669
[GDS_MITIGATION_HYPERVISOR] = "Unknown: Dependent on hypervisor status",
@@ -687,6 +689,7 @@ void update_gds_msr(void)
687689
rdmsrl(MSR_IA32_MCU_OPT_CTRL, mcu_ctrl);
688690
mcu_ctrl &= ~GDS_MITG_DIS;
689691
break;
692+
case GDS_MITIGATION_FORCE:
690693
case GDS_MITIGATION_UCODE_NEEDED:
691694
case GDS_MITIGATION_HYPERVISOR:
692695
return;
@@ -721,10 +724,23 @@ static void __init gds_select_mitigation(void)
721724

722725
/* No microcode */
723726
if (!(x86_read_arch_cap_msr() & ARCH_CAP_GDS_CTRL)) {
724-
gds_mitigation = GDS_MITIGATION_UCODE_NEEDED;
727+
if (gds_mitigation == GDS_MITIGATION_FORCE) {
728+
/*
729+
* This only needs to be done on the boot CPU so do it
730+
* here rather than in update_gds_msr()
731+
*/
732+
setup_clear_cpu_cap(X86_FEATURE_AVX);
733+
pr_warn("Microcode update needed! Disabling AVX as mitigation.\n");
734+
} else {
735+
gds_mitigation = GDS_MITIGATION_UCODE_NEEDED;
736+
}
725737
goto out;
726738
}
727739

740+
/* Microcode has mitigation, use it */
741+
if (gds_mitigation == GDS_MITIGATION_FORCE)
742+
gds_mitigation = GDS_MITIGATION_FULL;
743+
728744
rdmsrl(MSR_IA32_MCU_OPT_CTRL, mcu_ctrl);
729745
if (mcu_ctrl & GDS_MITG_LOCKED) {
730746
if (gds_mitigation == GDS_MITIGATION_OFF)
@@ -755,6 +771,8 @@ static int __init gds_parse_cmdline(char *str)
755771

756772
if (!strcmp(str, "off"))
757773
gds_mitigation = GDS_MITIGATION_OFF;
774+
else if (!strcmp(str, "force"))
775+
gds_mitigation = GDS_MITIGATION_FORCE;
758776

759777
return 0;
760778
}

0 commit comments

Comments
 (0)