Skip to content

Commit 4c92057

Browse files
jpoimboeKAGA-KOKO
authored andcommitted
Documentation: Add swapgs description to the Spectre v1 documentation
Add documentation to the Spectre document about the new swapgs variant of Spectre v1. Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]>
1 parent 7a30bdd commit 4c92057

File tree

1 file changed

+80
-8
lines changed

1 file changed

+80
-8
lines changed

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

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ Related CVEs
4141

4242
The following CVE entries describe Spectre variants:
4343

44-
============= ======================= =================
44+
============= ======================= ==========================
4545
CVE-2017-5753 Bounds check bypass Spectre variant 1
4646
CVE-2017-5715 Branch target injection Spectre variant 2
47-
============= ======================= =================
47+
CVE-2019-1125 Spectre v1 swapgs Spectre variant 1 (swapgs)
48+
============= ======================= ==========================
4849

4950
Problem
5051
-------
@@ -78,6 +79,13 @@ There are some extensions of Spectre variant 1 attacks for reading data
7879
over the network, see :ref:`[12] <spec_ref12>`. However such attacks
7980
are difficult, low bandwidth, fragile, and are considered low risk.
8081

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+
8189
Spectre variant 2 (Branch Target Injection)
8290
-------------------------------------------
8391

@@ -132,6 +140,9 @@ not cover all possible attack vectors.
132140
1. A user process attacking the kernel
133141
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
134142

143+
Spectre variant 1
144+
~~~~~~~~~~~~~~~~~
145+
135146
The attacker passes a parameter to the kernel via a register or
136147
via a known address in memory during a syscall. Such parameter may
137148
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.
144155
potentially be influenced for Spectre attacks, new "nospec" accessor
145156
macros are used to prevent speculative loading of data.
146157

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
148192
target buffer (BTB) before issuing syscall to launch an attack.
149193
After entering the kernel, the kernel could use the poisoned branch
150194
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:
280324

281325
The possible values in this file are:
282326

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.
288339

289340
However, the protections are put in place on a case by case basis,
290341
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
366417
1. Kernel mitigation
367418
^^^^^^^^^^^^^^^^^^^^
368419

420+
Spectre variant 1
421+
~~~~~~~~~~~~~~~~~
422+
369423
For the Spectre variant 1, vulnerable kernel code (as determined
370424
by code audit or scanning tools) is annotated on a case by case
371425
basis to use nospec accessor macros for bounds clipping :ref:`[2]
372426
<spec_ref2>` to avoid any usable disclosure gadgets. However, it may
373427
not cover all attack vectors for Spectre variant 1.
374428

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+
375441
For Spectre variant 2 mitigation, the compiler turns indirect calls or
376442
jumps in the kernel into equivalent return trampolines (retpolines)
377443
:ref:`[3] <spec_ref3>` :ref:`[9] <spec_ref9>` to go to the target
@@ -473,6 +539,12 @@ Mitigation control on the kernel command line
473539
Spectre variant 2 mitigation can be disabled or force enabled at the
474540
kernel command line.
475541

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+
476548
nospectre_v2
477549

478550
[X86] Disable all mitigations for the Spectre variant 2

0 commit comments

Comments
 (0)