Skip to content

Commit 553a5c0

Browse files
Daniel Sneddonhansendc
authored andcommitted
x86/speculation: Add force option to GDS mitigation
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]>
1 parent 8974eb5 commit 553a5c0

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
@@ -1633,7 +1633,13 @@
16331633

16341634
This issue is mitigated by default in updated microcode.
16351635
The mitigation may have a performance impact but can be
1636-
disabled.
1636+
disabled. On systems without the microcode mitigation
1637+
disabling AVX serves as a mitigation.
1638+
1639+
force: Disable AVX to mitigate systems without
1640+
microcode mitigation. No effect if the microcode
1641+
mitigation is present. Known to cause crashes in
1642+
userspace with buggy AVX enumeration.
16371643

16381644
off: Disable GDS mitigation.
16391645

arch/x86/kernel/cpu/bugs.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ early_param("l1d_flush", l1d_flush_parse_cmdline);
653653
enum gds_mitigations {
654654
GDS_MITIGATION_OFF,
655655
GDS_MITIGATION_UCODE_NEEDED,
656+
GDS_MITIGATION_FORCE,
656657
GDS_MITIGATION_FULL,
657658
GDS_MITIGATION_FULL_LOCKED,
658659
GDS_MITIGATION_HYPERVISOR,
@@ -663,6 +664,7 @@ static enum gds_mitigations gds_mitigation __ro_after_init = GDS_MITIGATION_FULL
663664
static const char * const gds_strings[] = {
664665
[GDS_MITIGATION_OFF] = "Vulnerable",
665666
[GDS_MITIGATION_UCODE_NEEDED] = "Vulnerable: No microcode",
667+
[GDS_MITIGATION_FORCE] = "Mitigation: AVX disabled, no microcode",
666668
[GDS_MITIGATION_FULL] = "Mitigation: Microcode",
667669
[GDS_MITIGATION_FULL_LOCKED] = "Mitigation: Microcode (locked)",
668670
[GDS_MITIGATION_HYPERVISOR] = "Unknown: Dependent on hypervisor status",
@@ -688,6 +690,7 @@ void update_gds_msr(void)
688690
rdmsrl(MSR_IA32_MCU_OPT_CTRL, mcu_ctrl);
689691
mcu_ctrl &= ~GDS_MITG_DIS;
690692
break;
693+
case GDS_MITIGATION_FORCE:
691694
case GDS_MITIGATION_UCODE_NEEDED:
692695
case GDS_MITIGATION_HYPERVISOR:
693696
return;
@@ -722,10 +725,23 @@ static void __init gds_select_mitigation(void)
722725

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

741+
/* Microcode has mitigation, use it */
742+
if (gds_mitigation == GDS_MITIGATION_FORCE)
743+
gds_mitigation = GDS_MITIGATION_FULL;
744+
729745
rdmsrl(MSR_IA32_MCU_OPT_CTRL, mcu_ctrl);
730746
if (mcu_ctrl & GDS_MITG_LOCKED) {
731747
if (gds_mitigation == GDS_MITIGATION_OFF)
@@ -756,6 +772,8 @@ static int __init gds_parse_cmdline(char *str)
756772

757773
if (!strcmp(str, "off"))
758774
gds_mitigation = GDS_MITIGATION_OFF;
775+
else if (!strcmp(str, "force"))
776+
gds_mitigation = GDS_MITIGATION_FORCE;
759777

760778
return 0;
761779
}

0 commit comments

Comments
 (0)