xref: /linux/Documentation/admin-guide/hw-vuln/mds.rst (revision 5999bbe7a6ea3c62029532ec84dc06003a1fa258)
1*5999bbe7SThomas GleixnerMDS - Microarchitectural Data Sampling
2*5999bbe7SThomas Gleixner======================================
3*5999bbe7SThomas Gleixner
4*5999bbe7SThomas GleixnerMicroarchitectural Data Sampling is a hardware vulnerability which allows
5*5999bbe7SThomas Gleixnerunprivileged speculative access to data which is available in various CPU
6*5999bbe7SThomas Gleixnerinternal buffers.
7*5999bbe7SThomas Gleixner
8*5999bbe7SThomas GleixnerAffected processors
9*5999bbe7SThomas Gleixner-------------------
10*5999bbe7SThomas Gleixner
11*5999bbe7SThomas GleixnerThis vulnerability affects a wide range of Intel processors. The
12*5999bbe7SThomas Gleixnervulnerability is not present on:
13*5999bbe7SThomas Gleixner
14*5999bbe7SThomas Gleixner   - Processors from AMD, Centaur and other non Intel vendors
15*5999bbe7SThomas Gleixner
16*5999bbe7SThomas Gleixner   - Older processor models, where the CPU family is < 6
17*5999bbe7SThomas Gleixner
18*5999bbe7SThomas Gleixner   - Some Atoms (Bonnell, Saltwell, Goldmont, GoldmontPlus)
19*5999bbe7SThomas Gleixner
20*5999bbe7SThomas Gleixner   - Intel processors which have the ARCH_CAP_MDS_NO bit set in the
21*5999bbe7SThomas Gleixner     IA32_ARCH_CAPABILITIES MSR.
22*5999bbe7SThomas Gleixner
23*5999bbe7SThomas GleixnerWhether a processor is affected or not can be read out from the MDS
24*5999bbe7SThomas Gleixnervulnerability file in sysfs. See :ref:`mds_sys_info`.
25*5999bbe7SThomas Gleixner
26*5999bbe7SThomas GleixnerNot all processors are affected by all variants of MDS, but the mitigation
27*5999bbe7SThomas Gleixneris identical for all of them so the kernel treats them as a single
28*5999bbe7SThomas Gleixnervulnerability.
29*5999bbe7SThomas Gleixner
30*5999bbe7SThomas GleixnerRelated CVEs
31*5999bbe7SThomas Gleixner------------
32*5999bbe7SThomas Gleixner
33*5999bbe7SThomas GleixnerThe following CVE entries are related to the MDS vulnerability:
34*5999bbe7SThomas Gleixner
35*5999bbe7SThomas Gleixner   ==============  =====  ==============================================
36*5999bbe7SThomas Gleixner   CVE-2018-12126  MSBDS  Microarchitectural Store Buffer Data Sampling
37*5999bbe7SThomas Gleixner   CVE-2018-12130  MFBDS  Microarchitectural Fill Buffer Data Sampling
38*5999bbe7SThomas Gleixner   CVE-2018-12127  MLPDS  Microarchitectural Load Port Data Sampling
39*5999bbe7SThomas Gleixner   ==============  =====  ==============================================
40*5999bbe7SThomas Gleixner
41*5999bbe7SThomas GleixnerProblem
42*5999bbe7SThomas Gleixner-------
43*5999bbe7SThomas Gleixner
44*5999bbe7SThomas GleixnerWhen performing store, load, L1 refill operations, processors write data
45*5999bbe7SThomas Gleixnerinto temporary microarchitectural structures (buffers). The data in the
46*5999bbe7SThomas Gleixnerbuffer can be forwarded to load operations as an optimization.
47*5999bbe7SThomas Gleixner
48*5999bbe7SThomas GleixnerUnder certain conditions, usually a fault/assist caused by a load
49*5999bbe7SThomas Gleixneroperation, data unrelated to the load memory address can be speculatively
50*5999bbe7SThomas Gleixnerforwarded from the buffers. Because the load operation causes a fault or
51*5999bbe7SThomas Gleixnerassist and its result will be discarded, the forwarded data will not cause
52*5999bbe7SThomas Gleixnerincorrect program execution or state changes. But a malicious operation
53*5999bbe7SThomas Gleixnermay be able to forward this speculative data to a disclosure gadget which
54*5999bbe7SThomas Gleixnerallows in turn to infer the value via a cache side channel attack.
55*5999bbe7SThomas Gleixner
56*5999bbe7SThomas GleixnerBecause the buffers are potentially shared between Hyper-Threads cross
57*5999bbe7SThomas GleixnerHyper-Thread attacks are possible.
58*5999bbe7SThomas Gleixner
59*5999bbe7SThomas GleixnerDeeper technical information is available in the MDS specific x86
60*5999bbe7SThomas Gleixnerarchitecture section: :ref:`Documentation/x86/mds.rst <mds>`.
61*5999bbe7SThomas Gleixner
62*5999bbe7SThomas Gleixner
63*5999bbe7SThomas GleixnerAttack scenarios
64*5999bbe7SThomas Gleixner----------------
65*5999bbe7SThomas Gleixner
66*5999bbe7SThomas GleixnerAttacks against the MDS vulnerabilities can be mounted from malicious non
67*5999bbe7SThomas Gleixnerpriviledged user space applications running on hosts or guest. Malicious
68*5999bbe7SThomas Gleixnerguest OSes can obviously mount attacks as well.
69*5999bbe7SThomas Gleixner
70*5999bbe7SThomas GleixnerContrary to other speculation based vulnerabilities the MDS vulnerability
71*5999bbe7SThomas Gleixnerdoes not allow the attacker to control the memory target address. As a
72*5999bbe7SThomas Gleixnerconsequence the attacks are purely sampling based, but as demonstrated with
73*5999bbe7SThomas Gleixnerthe TLBleed attack samples can be postprocessed successfully.
74*5999bbe7SThomas Gleixner
75*5999bbe7SThomas GleixnerWeb-Browsers
76*5999bbe7SThomas Gleixner^^^^^^^^^^^^
77*5999bbe7SThomas Gleixner
78*5999bbe7SThomas Gleixner  It's unclear whether attacks through Web-Browsers are possible at
79*5999bbe7SThomas Gleixner  all. The exploitation through Java-Script is considered very unlikely,
80*5999bbe7SThomas Gleixner  but other widely used web technologies like Webassembly could possibly be
81*5999bbe7SThomas Gleixner  abused.
82*5999bbe7SThomas Gleixner
83*5999bbe7SThomas Gleixner
84*5999bbe7SThomas Gleixner.. _mds_sys_info:
85*5999bbe7SThomas Gleixner
86*5999bbe7SThomas GleixnerMDS system information
87*5999bbe7SThomas Gleixner-----------------------
88*5999bbe7SThomas Gleixner
89*5999bbe7SThomas GleixnerThe Linux kernel provides a sysfs interface to enumerate the current MDS
90*5999bbe7SThomas Gleixnerstatus of the system: whether the system is vulnerable, and which
91*5999bbe7SThomas Gleixnermitigations are active. The relevant sysfs file is:
92*5999bbe7SThomas Gleixner
93*5999bbe7SThomas Gleixner/sys/devices/system/cpu/vulnerabilities/mds
94*5999bbe7SThomas Gleixner
95*5999bbe7SThomas GleixnerThe possible values in this file are:
96*5999bbe7SThomas Gleixner
97*5999bbe7SThomas Gleixner  =========================================   =================================
98*5999bbe7SThomas Gleixner  'Not affected'				The processor is not vulnerable
99*5999bbe7SThomas Gleixner
100*5999bbe7SThomas Gleixner  'Vulnerable'					The processor is vulnerable,
101*5999bbe7SThomas Gleixner						but no mitigation enabled
102*5999bbe7SThomas Gleixner
103*5999bbe7SThomas Gleixner  'Vulnerable: Clear CPU buffers attempted'	The processor is vulnerable but
104*5999bbe7SThomas Gleixner						microcode is not updated.
105*5999bbe7SThomas Gleixner						The mitigation is enabled on a
106*5999bbe7SThomas Gleixner						best effort basis.
107*5999bbe7SThomas Gleixner						See :ref:`vmwerv`
108*5999bbe7SThomas Gleixner
109*5999bbe7SThomas Gleixner  'Mitigation: CPU buffer clear'		The processor is vulnerable and the
110*5999bbe7SThomas Gleixner						CPU buffer clearing mitigation is
111*5999bbe7SThomas Gleixner						enabled.
112*5999bbe7SThomas Gleixner  =========================================   =================================
113*5999bbe7SThomas Gleixner
114*5999bbe7SThomas GleixnerIf the processor is vulnerable then the following information is appended
115*5999bbe7SThomas Gleixnerto the above information:
116*5999bbe7SThomas Gleixner
117*5999bbe7SThomas Gleixner    ========================  ============================================
118*5999bbe7SThomas Gleixner    'SMT vulnerable'          SMT is enabled
119*5999bbe7SThomas Gleixner    'SMT mitigated'           SMT is enabled and mitigated
120*5999bbe7SThomas Gleixner    'SMT disabled'            SMT is disabled
121*5999bbe7SThomas Gleixner    'SMT Host state unknown'  Kernel runs in a VM, Host SMT state unknown
122*5999bbe7SThomas Gleixner    ========================  ============================================
123*5999bbe7SThomas Gleixner
124*5999bbe7SThomas Gleixner.. _vmwerv:
125*5999bbe7SThomas Gleixner
126*5999bbe7SThomas GleixnerBest effort mitigation mode
127*5999bbe7SThomas Gleixner^^^^^^^^^^^^^^^^^^^^^^^^^^^
128*5999bbe7SThomas Gleixner
129*5999bbe7SThomas Gleixner  If the processor is vulnerable, but the availability of the microcode based
130*5999bbe7SThomas Gleixner  mitigation mechanism is not advertised via CPUID the kernel selects a best
131*5999bbe7SThomas Gleixner  effort mitigation mode.  This mode invokes the mitigation instructions
132*5999bbe7SThomas Gleixner  without a guarantee that they clear the CPU buffers.
133*5999bbe7SThomas Gleixner
134*5999bbe7SThomas Gleixner  This is done to address virtualization scenarios where the host has the
135*5999bbe7SThomas Gleixner  microcode update applied, but the hypervisor is not yet updated to expose
136*5999bbe7SThomas Gleixner  the CPUID to the guest. If the host has updated microcode the protection
137*5999bbe7SThomas Gleixner  takes effect otherwise a few cpu cycles are wasted pointlessly.
138*5999bbe7SThomas Gleixner
139*5999bbe7SThomas Gleixner  The state in the mds sysfs file reflects this situation accordingly.
140*5999bbe7SThomas Gleixner
141*5999bbe7SThomas Gleixner
142*5999bbe7SThomas GleixnerMitigation mechanism
143*5999bbe7SThomas Gleixner-------------------------
144*5999bbe7SThomas Gleixner
145*5999bbe7SThomas GleixnerThe kernel detects the affected CPUs and the presence of the microcode
146*5999bbe7SThomas Gleixnerwhich is required.
147*5999bbe7SThomas Gleixner
148*5999bbe7SThomas GleixnerIf a CPU is affected and the microcode is available, then the kernel
149*5999bbe7SThomas Gleixnerenables the mitigation by default. The mitigation can be controlled at boot
150*5999bbe7SThomas Gleixnertime via a kernel command line option. See
151*5999bbe7SThomas Gleixner:ref:`mds_mitigation_control_command_line`.
152*5999bbe7SThomas Gleixner
153*5999bbe7SThomas Gleixner.. _cpu_buffer_clear:
154*5999bbe7SThomas Gleixner
155*5999bbe7SThomas GleixnerCPU buffer clearing
156*5999bbe7SThomas Gleixner^^^^^^^^^^^^^^^^^^^
157*5999bbe7SThomas Gleixner
158*5999bbe7SThomas Gleixner  The mitigation for MDS clears the affected CPU buffers on return to user
159*5999bbe7SThomas Gleixner  space and when entering a guest.
160*5999bbe7SThomas Gleixner
161*5999bbe7SThomas Gleixner  If SMT is enabled it also clears the buffers on idle entry when the CPU
162*5999bbe7SThomas Gleixner  is only affected by MSBDS and not any other MDS variant, because the
163*5999bbe7SThomas Gleixner  other variants cannot be protected against cross Hyper-Thread attacks.
164*5999bbe7SThomas Gleixner
165*5999bbe7SThomas Gleixner  For CPUs which are only affected by MSBDS the user space, guest and idle
166*5999bbe7SThomas Gleixner  transition mitigations are sufficient and SMT is not affected.
167*5999bbe7SThomas Gleixner
168*5999bbe7SThomas Gleixner.. _virt_mechanism:
169*5999bbe7SThomas Gleixner
170*5999bbe7SThomas GleixnerVirtualization mitigation
171*5999bbe7SThomas Gleixner^^^^^^^^^^^^^^^^^^^^^^^^^
172*5999bbe7SThomas Gleixner
173*5999bbe7SThomas Gleixner  The protection for host to guest transition depends on the L1TF
174*5999bbe7SThomas Gleixner  vulnerability of the CPU:
175*5999bbe7SThomas Gleixner
176*5999bbe7SThomas Gleixner  - CPU is affected by L1TF:
177*5999bbe7SThomas Gleixner
178*5999bbe7SThomas Gleixner    If the L1D flush mitigation is enabled and up to date microcode is
179*5999bbe7SThomas Gleixner    available, the L1D flush mitigation is automatically protecting the
180*5999bbe7SThomas Gleixner    guest transition.
181*5999bbe7SThomas Gleixner
182*5999bbe7SThomas Gleixner    If the L1D flush mitigation is disabled then the MDS mitigation is
183*5999bbe7SThomas Gleixner    invoked explicit when the host MDS mitigation is enabled.
184*5999bbe7SThomas Gleixner
185*5999bbe7SThomas Gleixner    For details on L1TF and virtualization see:
186*5999bbe7SThomas Gleixner    :ref:`Documentation/admin-guide/hw-vuln//l1tf.rst <mitigation_control_kvm>`.
187*5999bbe7SThomas Gleixner
188*5999bbe7SThomas Gleixner  - CPU is not affected by L1TF:
189*5999bbe7SThomas Gleixner
190*5999bbe7SThomas Gleixner    CPU buffers are flushed before entering the guest when the host MDS
191*5999bbe7SThomas Gleixner    mitigation is enabled.
192*5999bbe7SThomas Gleixner
193*5999bbe7SThomas Gleixner  The resulting MDS protection matrix for the host to guest transition:
194*5999bbe7SThomas Gleixner
195*5999bbe7SThomas Gleixner  ============ ===== ============= ============ =================
196*5999bbe7SThomas Gleixner   L1TF         MDS   VMX-L1FLUSH   Host MDS     MDS-State
197*5999bbe7SThomas Gleixner
198*5999bbe7SThomas Gleixner   Don't care   No    Don't care    N/A          Not affected
199*5999bbe7SThomas Gleixner
200*5999bbe7SThomas Gleixner   Yes          Yes   Disabled      Off          Vulnerable
201*5999bbe7SThomas Gleixner
202*5999bbe7SThomas Gleixner   Yes          Yes   Disabled      Full         Mitigated
203*5999bbe7SThomas Gleixner
204*5999bbe7SThomas Gleixner   Yes          Yes   Enabled       Don't care   Mitigated
205*5999bbe7SThomas Gleixner
206*5999bbe7SThomas Gleixner   No           Yes   N/A           Off          Vulnerable
207*5999bbe7SThomas Gleixner
208*5999bbe7SThomas Gleixner   No           Yes   N/A           Full         Mitigated
209*5999bbe7SThomas Gleixner  ============ ===== ============= ============ =================
210*5999bbe7SThomas Gleixner
211*5999bbe7SThomas Gleixner  This only covers the host to guest transition, i.e. prevents leakage from
212*5999bbe7SThomas Gleixner  host to guest, but does not protect the guest internally. Guests need to
213*5999bbe7SThomas Gleixner  have their own protections.
214*5999bbe7SThomas Gleixner
215*5999bbe7SThomas Gleixner.. _xeon_phi:
216*5999bbe7SThomas Gleixner
217*5999bbe7SThomas GleixnerXEON PHI specific considerations
218*5999bbe7SThomas Gleixner^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
219*5999bbe7SThomas Gleixner
220*5999bbe7SThomas Gleixner  The XEON PHI processor family is affected by MSBDS which can be exploited
221*5999bbe7SThomas Gleixner  cross Hyper-Threads when entering idle states. Some XEON PHI variants allow
222*5999bbe7SThomas Gleixner  to use MWAIT in user space (Ring 3) which opens an potential attack vector
223*5999bbe7SThomas Gleixner  for malicious user space. The exposure can be disabled on the kernel
224*5999bbe7SThomas Gleixner  command line with the 'ring3mwait=disable' command line option.
225*5999bbe7SThomas Gleixner
226*5999bbe7SThomas Gleixner  XEON PHI is not affected by the other MDS variants and MSBDS is mitigated
227*5999bbe7SThomas Gleixner  before the CPU enters a idle state. As XEON PHI is not affected by L1TF
228*5999bbe7SThomas Gleixner  either disabling SMT is not required for full protection.
229*5999bbe7SThomas Gleixner
230*5999bbe7SThomas Gleixner.. _mds_smt_control:
231*5999bbe7SThomas Gleixner
232*5999bbe7SThomas GleixnerSMT control
233*5999bbe7SThomas Gleixner^^^^^^^^^^^
234*5999bbe7SThomas Gleixner
235*5999bbe7SThomas Gleixner  All MDS variants except MSBDS can be attacked cross Hyper-Threads. That
236*5999bbe7SThomas Gleixner  means on CPUs which are affected by MFBDS or MLPDS it is necessary to
237*5999bbe7SThomas Gleixner  disable SMT for full protection. These are most of the affected CPUs; the
238*5999bbe7SThomas Gleixner  exception is XEON PHI, see :ref:`xeon_phi`.
239*5999bbe7SThomas Gleixner
240*5999bbe7SThomas Gleixner  Disabling SMT can have a significant performance impact, but the impact
241*5999bbe7SThomas Gleixner  depends on the type of workloads.
242*5999bbe7SThomas Gleixner
243*5999bbe7SThomas Gleixner  See the relevant chapter in the L1TF mitigation documentation for details:
244*5999bbe7SThomas Gleixner  :ref:`Documentation/admin-guide/hw-vuln/l1tf.rst <smt_control>`.
245*5999bbe7SThomas Gleixner
246*5999bbe7SThomas Gleixner
247*5999bbe7SThomas Gleixner.. _mds_mitigation_control_command_line:
248*5999bbe7SThomas Gleixner
249*5999bbe7SThomas GleixnerMitigation control on the kernel command line
250*5999bbe7SThomas Gleixner---------------------------------------------
251*5999bbe7SThomas Gleixner
252*5999bbe7SThomas GleixnerThe kernel command line allows to control the MDS mitigations at boot
253*5999bbe7SThomas Gleixnertime with the option "mds=". The valid arguments for this option are:
254*5999bbe7SThomas Gleixner
255*5999bbe7SThomas Gleixner  ============  =============================================================
256*5999bbe7SThomas Gleixner  full		If the CPU is vulnerable, enable all available mitigations
257*5999bbe7SThomas Gleixner		for the MDS vulnerability, CPU buffer clearing on exit to
258*5999bbe7SThomas Gleixner		userspace and when entering a VM. Idle transitions are
259*5999bbe7SThomas Gleixner		protected as well if SMT is enabled.
260*5999bbe7SThomas Gleixner
261*5999bbe7SThomas Gleixner		It does not automatically disable SMT.
262*5999bbe7SThomas Gleixner
263*5999bbe7SThomas Gleixner  off		Disables MDS mitigations completely.
264*5999bbe7SThomas Gleixner
265*5999bbe7SThomas Gleixner  ============  =============================================================
266*5999bbe7SThomas Gleixner
267*5999bbe7SThomas GleixnerNot specifying this option is equivalent to "mds=full".
268*5999bbe7SThomas Gleixner
269*5999bbe7SThomas Gleixner
270*5999bbe7SThomas GleixnerMitigation selection guide
271*5999bbe7SThomas Gleixner--------------------------
272*5999bbe7SThomas Gleixner
273*5999bbe7SThomas Gleixner1. Trusted userspace
274*5999bbe7SThomas Gleixner^^^^^^^^^^^^^^^^^^^^
275*5999bbe7SThomas Gleixner
276*5999bbe7SThomas Gleixner   If all userspace applications are from a trusted source and do not
277*5999bbe7SThomas Gleixner   execute untrusted code which is supplied externally, then the mitigation
278*5999bbe7SThomas Gleixner   can be disabled.
279*5999bbe7SThomas Gleixner
280*5999bbe7SThomas Gleixner
281*5999bbe7SThomas Gleixner2. Virtualization with trusted guests
282*5999bbe7SThomas Gleixner^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
283*5999bbe7SThomas Gleixner
284*5999bbe7SThomas Gleixner   The same considerations as above versus trusted user space apply.
285*5999bbe7SThomas Gleixner
286*5999bbe7SThomas Gleixner3. Virtualization with untrusted guests
287*5999bbe7SThomas Gleixner^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
288*5999bbe7SThomas Gleixner
289*5999bbe7SThomas Gleixner   The protection depends on the state of the L1TF mitigations.
290*5999bbe7SThomas Gleixner   See :ref:`virt_mechanism`.
291*5999bbe7SThomas Gleixner
292*5999bbe7SThomas Gleixner   If the MDS mitigation is enabled and SMT is disabled, guest to host and
293*5999bbe7SThomas Gleixner   guest to guest attacks are prevented.
294*5999bbe7SThomas Gleixner
295*5999bbe7SThomas Gleixner.. _mds_default_mitigations:
296*5999bbe7SThomas Gleixner
297*5999bbe7SThomas GleixnerDefault mitigations
298*5999bbe7SThomas Gleixner-------------------
299*5999bbe7SThomas Gleixner
300*5999bbe7SThomas Gleixner  The kernel default mitigations for vulnerable processors are:
301*5999bbe7SThomas Gleixner
302*5999bbe7SThomas Gleixner  - Enable CPU buffer clearing
303*5999bbe7SThomas Gleixner
304*5999bbe7SThomas Gleixner  The kernel does not by default enforce the disabling of SMT, which leaves
305*5999bbe7SThomas Gleixner  SMT systems vulnerable when running untrusted code. The same rationale as
306*5999bbe7SThomas Gleixner  for L1TF applies.
307*5999bbe7SThomas Gleixner  See :ref:`Documentation/admin-guide/hw-vuln//l1tf.rst <default_mitigations>`.
308