@@ -41,10 +41,11 @@ Related CVEs
41
41
42
42
The following CVE entries describe Spectre variants:
43
43
44
- ============= ======================= =================
44
+ ============= ======================= ==========================
45
45
CVE-2017-5753 Bounds check bypass Spectre variant 1
46
46
CVE-2017-5715 Branch target injection Spectre variant 2
47
- ============= ======================= =================
47
+ CVE-2019-1125 Spectre v1 swapgs Spectre variant 1 (swapgs)
48
+ ============= ======================= ==========================
48
49
49
50
Problem
50
51
-------
@@ -78,6 +79,13 @@ There are some extensions of Spectre variant 1 attacks for reading data
78
79
over the network, see :ref: `[12] <spec_ref12 >`. However such attacks
79
80
are difficult, low bandwidth, fragile, and are considered low risk.
80
81
82
+ Note that, despite "Bounds Check Bypass" name, Spectre variant 1 is not
83
+ only about user-controlled array bounds checks. It can affect any
84
+ conditional checks. The kernel entry code interrupt, exception, and NMI
85
+ handlers all have conditional swapgs checks. Those may be problematic
86
+ in the context of Spectre v1, as kernel code can speculatively run with
87
+ a user GS.
88
+
81
89
Spectre variant 2 (Branch Target Injection)
82
90
-------------------------------------------
83
91
@@ -132,6 +140,9 @@ not cover all possible attack vectors.
132
140
1. A user process attacking the kernel
133
141
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
134
142
143
+ Spectre variant 1
144
+ ~~~~~~~~~~~~~~~~~
145
+
135
146
The attacker passes a parameter to the kernel via a register or
136
147
via a known address in memory during a syscall. Such parameter may
137
148
be used later by the kernel as an index to an array or to derive
@@ -144,7 +155,40 @@ not cover all possible attack vectors.
144
155
potentially be influenced for Spectre attacks, new "nospec" accessor
145
156
macros are used to prevent speculative loading of data.
146
157
147
- Spectre variant 2 attacker can :ref: `poison <poison_btb >` the branch
158
+ Spectre variant 1 (swapgs)
159
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
160
+
161
+ An attacker can train the branch predictor to speculatively skip the
162
+ swapgs path for an interrupt or exception. If they initialize
163
+ the GS register to a user-space value, if the swapgs is speculatively
164
+ skipped, subsequent GS-related percpu accesses in the speculation
165
+ window will be done with the attacker-controlled GS value. This
166
+ could cause privileged memory to be accessed and leaked.
167
+
168
+ For example:
169
+
170
+ ::
171
+
172
+ if (coming from user space)
173
+ swapgs
174
+ mov %gs:<percpu_offset>, %reg
175
+ mov (%reg), %reg1
176
+
177
+ When coming from user space, the CPU can speculatively skip the
178
+ swapgs, and then do a speculative percpu load using the user GS
179
+ value. So the user can speculatively force a read of any kernel
180
+ value. If a gadget exists which uses the percpu value as an address
181
+ in another load/store, then the contents of the kernel value may
182
+ become visible via an L1 side channel attack.
183
+
184
+ A similar attack exists when coming from kernel space. The CPU can
185
+ speculatively do the swapgs, causing the user GS to get used for the
186
+ rest of the speculative window.
187
+
188
+ Spectre variant 2
189
+ ~~~~~~~~~~~~~~~~~
190
+
191
+ A spectre variant 2 attacker can :ref: `poison <poison_btb >` the branch
148
192
target buffer (BTB) before issuing syscall to launch an attack.
149
193
After entering the kernel, the kernel could use the poisoned branch
150
194
target buffer on indirect jump and jump to gadget code in speculative
@@ -280,11 +324,18 @@ The sysfs file showing Spectre variant 1 mitigation status is:
280
324
281
325
The possible values in this file are:
282
326
283
- ======================================= =================================
284
- 'Mitigation: __user pointer sanitation' Protection in kernel on a case by
285
- case base with explicit pointer
286
- sanitation.
287
- ======================================= =================================
327
+ .. list-table ::
328
+
329
+ * - 'Not affected'
330
+ - The processor is not vulnerable.
331
+ * - 'Vulnerable: __user pointer sanitization and usercopy barriers only; no swapgs barriers'
332
+ - The swapgs protections are disabled; otherwise it has
333
+ protection in the kernel on a case by case base with explicit
334
+ pointer sanitation and usercopy LFENCE barriers.
335
+ * - 'Mitigation: usercopy/swapgs barriers and __user pointer sanitization'
336
+ - Protection in the kernel on a case by case base with explicit
337
+ pointer sanitation, usercopy LFENCE barriers, and swapgs LFENCE
338
+ barriers.
288
339
289
340
However, the protections are put in place on a case by case basis,
290
341
and there is no guarantee that all possible attack vectors for Spectre
@@ -366,12 +417,27 @@ Turning on mitigation for Spectre variant 1 and Spectre variant 2
366
417
1. Kernel mitigation
367
418
^^^^^^^^^^^^^^^^^^^^
368
419
420
+ Spectre variant 1
421
+ ~~~~~~~~~~~~~~~~~
422
+
369
423
For the Spectre variant 1, vulnerable kernel code (as determined
370
424
by code audit or scanning tools) is annotated on a case by case
371
425
basis to use nospec accessor macros for bounds clipping :ref: `[2]
372
426
<spec_ref2>` to avoid any usable disclosure gadgets. However, it may
373
427
not cover all attack vectors for Spectre variant 1.
374
428
429
+ Copy-from-user code has an LFENCE barrier to prevent the access_ok()
430
+ check from being mis-speculated. The barrier is done by the
431
+ barrier_nospec() macro.
432
+
433
+ For the swapgs variant of Spectre variant 1, LFENCE barriers are
434
+ added to interrupt, exception and NMI entry where needed. These
435
+ barriers are done by the FENCE_SWAPGS_KERNEL_ENTRY and
436
+ FENCE_SWAPGS_USER_ENTRY macros.
437
+
438
+ Spectre variant 2
439
+ ~~~~~~~~~~~~~~~~~
440
+
375
441
For Spectre variant 2 mitigation, the compiler turns indirect calls or
376
442
jumps in the kernel into equivalent return trampolines (retpolines)
377
443
:ref: `[3] <spec_ref3 >` :ref: `[9] <spec_ref9 >` to go to the target
@@ -473,6 +539,12 @@ Mitigation control on the kernel command line
473
539
Spectre variant 2 mitigation can be disabled or force enabled at the
474
540
kernel command line.
475
541
542
+ nospectre_v1
543
+
544
+ [X86,PPC] Disable mitigations for Spectre Variant 1
545
+ (bounds check bypass). With this option data leaks are
546
+ possible in the system.
547
+
476
548
nospectre_v2
477
549
478
550
[X86] Disable all mitigations for the Spectre variant 2
0 commit comments