Skip to content

Commit 64094e7

Browse files
committed
Merge tag 'gds-for-linus-2023-08-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86/gds fixes from Dave Hansen: "Mitigate Gather Data Sampling issue: - Add Base GDS mitigation - Support GDS_NO under KVM - Fix a documentation typo" * tag 'gds-for-linus-2023-08-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: Documentation/x86: Fix backwards on/off logic about YMM support KVM: Add GDS_NO support to KVM x86/speculation: Add Kconfig option for GDS x86/speculation: Add force option to GDS mitigation x86/speculation: Add Gather Data Sampling mitigation
2 parents 138bcdd + 1b0fc03 commit 64094e7

File tree

12 files changed

+380
-29
lines changed

12 files changed

+380
-29
lines changed

Documentation/ABI/testing/sysfs-devices-system-cpu

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,17 +513,18 @@ Description: information about CPUs heterogeneity.
513513
cpu_capacity: capacity of cpuX.
514514

515515
What: /sys/devices/system/cpu/vulnerabilities
516+
/sys/devices/system/cpu/vulnerabilities/gather_data_sampling
517+
/sys/devices/system/cpu/vulnerabilities/itlb_multihit
518+
/sys/devices/system/cpu/vulnerabilities/l1tf
519+
/sys/devices/system/cpu/vulnerabilities/mds
516520
/sys/devices/system/cpu/vulnerabilities/meltdown
521+
/sys/devices/system/cpu/vulnerabilities/mmio_stale_data
522+
/sys/devices/system/cpu/vulnerabilities/retbleed
523+
/sys/devices/system/cpu/vulnerabilities/spec_store_bypass
517524
/sys/devices/system/cpu/vulnerabilities/spectre_v1
518525
/sys/devices/system/cpu/vulnerabilities/spectre_v2
519-
/sys/devices/system/cpu/vulnerabilities/spec_store_bypass
520-
/sys/devices/system/cpu/vulnerabilities/l1tf
521-
/sys/devices/system/cpu/vulnerabilities/mds
522526
/sys/devices/system/cpu/vulnerabilities/srbds
523527
/sys/devices/system/cpu/vulnerabilities/tsx_async_abort
524-
/sys/devices/system/cpu/vulnerabilities/itlb_multihit
525-
/sys/devices/system/cpu/vulnerabilities/mmio_stale_data
526-
/sys/devices/system/cpu/vulnerabilities/retbleed
527528
Date: January 2018
528529
Contact: Linux kernel mailing list <[email protected]>
529530
Description: Information about CPU vulnerabilities
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
GDS - Gather Data Sampling
4+
==========================
5+
6+
Gather Data Sampling is a hardware vulnerability which allows unprivileged
7+
speculative access to data which was previously stored in vector registers.
8+
9+
Problem
10+
-------
11+
When a gather instruction performs loads from memory, different data elements
12+
are merged into the destination vector register. However, when a gather
13+
instruction that is transiently executed encounters a fault, stale data from
14+
architectural or internal vector registers may get transiently forwarded to the
15+
destination vector register instead. This will allow a malicious attacker to
16+
infer stale data using typical side channel techniques like cache timing
17+
attacks. GDS is a purely sampling-based attack.
18+
19+
The attacker uses gather instructions to infer the stale vector register data.
20+
The victim does not need to do anything special other than use the vector
21+
registers. The victim does not need to use gather instructions to be
22+
vulnerable.
23+
24+
Because the buffers are shared between Hyper-Threads cross Hyper-Thread attacks
25+
are possible.
26+
27+
Attack scenarios
28+
----------------
29+
Without mitigation, GDS can infer stale data across virtually all
30+
permission boundaries:
31+
32+
Non-enclaves can infer SGX enclave data
33+
Userspace can infer kernel data
34+
Guests can infer data from hosts
35+
Guest can infer guest from other guests
36+
Users can infer data from other users
37+
38+
Because of this, it is important to ensure that the mitigation stays enabled in
39+
lower-privilege contexts like guests and when running outside SGX enclaves.
40+
41+
The hardware enforces the mitigation for SGX. Likewise, VMMs should ensure
42+
that guests are not allowed to disable the GDS mitigation. If a host erred and
43+
allowed this, a guest could theoretically disable GDS mitigation, mount an
44+
attack, and re-enable it.
45+
46+
Mitigation mechanism
47+
--------------------
48+
This issue is mitigated in microcode. The microcode defines the following new
49+
bits:
50+
51+
================================ === ============================
52+
IA32_ARCH_CAPABILITIES[GDS_CTRL] R/O Enumerates GDS vulnerability
53+
and mitigation support.
54+
IA32_ARCH_CAPABILITIES[GDS_NO] R/O Processor is not vulnerable.
55+
IA32_MCU_OPT_CTRL[GDS_MITG_DIS] R/W Disables the mitigation
56+
0 by default.
57+
IA32_MCU_OPT_CTRL[GDS_MITG_LOCK] R/W Locks GDS_MITG_DIS=0. Writes
58+
to GDS_MITG_DIS are ignored
59+
Can't be cleared once set.
60+
================================ === ============================
61+
62+
GDS can also be mitigated on systems that don't have updated microcode by
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 off 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.
70+
71+
Mitigation control on the kernel command line
72+
---------------------------------------------
73+
The mitigation can be disabled by setting "gather_data_sampling=off" or
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.
78+
79+
GDS System Information
80+
------------------------
81+
The kernel provides vulnerability status information through sysfs. For
82+
GDS this can be accessed by the following sysfs file:
83+
84+
/sys/devices/system/cpu/vulnerabilities/gather_data_sampling
85+
86+
The possible values contained in this file are:
87+
88+
============================== =============================================
89+
Not affected Processor not vulnerable.
90+
Vulnerable Processor vulnerable and mitigation disabled.
91+
Vulnerable: No microcode Processor vulnerable and microcode is missing
92+
mitigation.
93+
Mitigation: AVX disabled,
94+
no microcode Processor is vulnerable and microcode is missing
95+
mitigation. AVX disabled as mitigation.
96+
Mitigation: Microcode Processor is vulnerable and mitigation is in
97+
effect.
98+
Mitigation: Microcode (locked) Processor is vulnerable and mitigation is in
99+
effect and cannot be disabled.
100+
Unknown: Dependent on
101+
hypervisor status Running on a virtual guest processor that is
102+
affected but with no way to know if host
103+
processor is mitigated or vulnerable.
104+
============================== =============================================
105+
106+
GDS Default mitigation
107+
----------------------
108+
The updated microcode will enable the mitigation by default. The kernel's
109+
default action is to leave the mitigation enabled.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ are configurable at compile, boot or run time.
2020
processor_mmio_stale_data.rst
2121
cross-thread-rsb.rst
2222
srso
23+
gather_data_sampling.rst

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,26 @@
16231623
Format: off | on
16241624
default: on
16251625

1626+
gather_data_sampling=
1627+
[X86,INTEL] Control the Gather Data Sampling (GDS)
1628+
mitigation.
1629+
1630+
Gather Data Sampling is a hardware vulnerability which
1631+
allows unprivileged speculative access to data which was
1632+
previously stored in vector registers.
1633+
1634+
This issue is mitigated by default in updated microcode.
1635+
The mitigation may have a performance impact but can be
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.
1643+
1644+
off: Disable GDS mitigation.
1645+
16261646
gcov_persist= [GCOV] When non-zero (default), profiling data for
16271647
kernel modules is saved and remains accessible via
16281648
debugfs, even when the module is unloaded/reloaded.
@@ -3273,24 +3293,25 @@
32733293
Disable all optional CPU mitigations. This
32743294
improves system performance, but it may also
32753295
expose users to several CPU vulnerabilities.
3276-
Equivalent to: nopti [X86,PPC]
3277-
if nokaslr then kpti=0 [ARM64]
3278-
nospectre_v1 [X86,PPC]
3279-
nobp=0 [S390]
3280-
nospectre_v2 [X86,PPC,S390,ARM64]
3281-
spectre_v2_user=off [X86]
3282-
spec_store_bypass_disable=off [X86,PPC]
3283-
ssbd=force-off [ARM64]
3284-
nospectre_bhb [ARM64]
3296+
Equivalent to: if nokaslr then kpti=0 [ARM64]
3297+
gather_data_sampling=off [X86]
3298+
kvm.nx_huge_pages=off [X86]
32853299
l1tf=off [X86]
32863300
mds=off [X86]
3287-
tsx_async_abort=off [X86]
3288-
kvm.nx_huge_pages=off [X86]
3289-
srbds=off [X86,INTEL]
3301+
mmio_stale_data=off [X86]
32903302
no_entry_flush [PPC]
32913303
no_uaccess_flush [PPC]
3292-
mmio_stale_data=off [X86]
3304+
nobp=0 [S390]
3305+
nopti [X86,PPC]
3306+
nospectre_bhb [ARM64]
3307+
nospectre_v1 [X86,PPC]
3308+
nospectre_v2 [X86,PPC,S390,ARM64]
32933309
retbleed=off [X86]
3310+
spec_store_bypass_disable=off [X86,PPC]
3311+
spectre_v2_user=off [X86]
3312+
srbds=off [X86,INTEL]
3313+
ssbd=force-off [ARM64]
3314+
tsx_async_abort=off [X86]
32943315

32953316
Exceptions:
32963317
This does not have any effect on

arch/x86/Kconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,6 +2610,25 @@ config SLS
26102610
against straight line speculation. The kernel image might be slightly
26112611
larger.
26122612

2613+
config GDS_FORCE_MITIGATION
2614+
bool "Force GDS Mitigation"
2615+
depends on CPU_SUP_INTEL
2616+
default n
2617+
help
2618+
Gather Data Sampling (GDS) is a hardware vulnerability which allows
2619+
unprivileged speculative access to data which was previously stored in
2620+
vector registers.
2621+
2622+
This option is equivalent to setting gather_data_sampling=force on the
2623+
command line. The microcode mitigation is used if present, otherwise
2624+
AVX is disabled as a mitigation. On affected systems that are missing
2625+
the microcode any userspace code that unconditionally uses AVX will
2626+
break with this option set.
2627+
2628+
Setting this option on systems not vulnerable to GDS has no effect.
2629+
2630+
If in doubt, say N.
2631+
26132632
endif
26142633

26152634
config ARCH_HAS_ADD_PAGES

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@
491491
#define X86_BUG_RETBLEED X86_BUG(27) /* CPU is affected by RETBleed */
492492
#define X86_BUG_EIBRS_PBRSB X86_BUG(28) /* EIBRS is vulnerable to Post Barrier RSB Predictions */
493493
#define X86_BUG_SMT_RSB X86_BUG(29) /* CPU is vulnerable to Cross-Thread Return Address Predictions */
494+
#define X86_BUG_GDS X86_BUG(30) /* CPU is affected by Gather Data Sampling */
494495

495496
/* BUG word 2 */
496497
#define X86_BUG_SRSO X86_BUG(1*32 + 0) /* AMD SRSO bug */

arch/x86/include/asm/msr-index.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@
156156
* Not susceptible to Post-Barrier
157157
* Return Stack Buffer Predictions.
158158
*/
159+
#define ARCH_CAP_GDS_CTRL BIT(25) /*
160+
* CPU is vulnerable to Gather
161+
* Data Sampling (GDS) and
162+
* has controls for mitigation.
163+
*/
164+
#define ARCH_CAP_GDS_NO BIT(26) /*
165+
* CPU is not vulnerable to Gather
166+
* Data Sampling (GDS).
167+
*/
159168

160169
#define ARCH_CAP_XAPIC_DISABLE BIT(21) /*
161170
* IA32_XAPIC_DISABLE_STATUS MSR
@@ -179,6 +188,8 @@
179188
#define RNGDS_MITG_DIS BIT(0) /* SRBDS support */
180189
#define RTM_ALLOW BIT(1) /* TSX development mode */
181190
#define FB_CLEAR_DIS BIT(3) /* CPU Fill buffer clear disable */
191+
#define GDS_MITG_DIS BIT(4) /* Disable GDS mitigation */
192+
#define GDS_MITG_LOCKED BIT(5) /* GDS mitigation locked */
182193

183194
#define MSR_IA32_SYSENTER_CS 0x00000174
184195
#define MSR_IA32_SYSENTER_ESP 0x00000175

0 commit comments

Comments
 (0)