Skip to content

Commit 4a01e74

Browse files
committed
Merge tag 'x86_bugs_for_v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 spectre fixes from Borislav Petkov: - Mitigate Spectre v2-type Branch History Buffer attacks on machines which support eIBRS, i.e., the hardware-assisted speculation restriction after it has been shown that such machines are vulnerable even with the hardware mitigation. - Do not use the default LFENCE-based Spectre v2 mitigation on AMD as it is insufficient to mitigate such attacks. Instead, switch to retpolines on all AMD by default. - Update the docs and add some warnings for the obviously vulnerable cmdline configurations. * tag 'x86_bugs_for_v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/speculation: Warn about eIBRS + LFENCE + Unprivileged eBPF + SMT x86/speculation: Warn about Spectre v2 LFENCE mitigation x86/speculation: Update link to AMD speculation whitepaper x86/speculation: Use generic retpoline by default on AMD x86/speculation: Include unprivileged eBPF status in Spectre v2 mitigation reporting Documentation/hw-vuln: Update spectre doc x86/speculation: Add eIBRS + Retpoline options x86/speculation: Rename RETPOLINE_AMD to RETPOLINE_LFENCE
2 parents ea4424b + 0de05d0 commit 4a01e74

File tree

11 files changed

+230
-82
lines changed

11 files changed

+230
-82
lines changed

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

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ privileged data touched during the speculative execution.
6060
Spectre variant 1 attacks take advantage of speculative execution of
6161
conditional branches, while Spectre variant 2 attacks use speculative
6262
execution of indirect branches to leak privileged memory.
63-
See :ref:`[1] <spec_ref1>` :ref:`[5] <spec_ref5>` :ref:`[7] <spec_ref7>`
64-
:ref:`[10] <spec_ref10>` :ref:`[11] <spec_ref11>`.
63+
See :ref:`[1] <spec_ref1>` :ref:`[5] <spec_ref5>` :ref:`[6] <spec_ref6>`
64+
:ref:`[7] <spec_ref7>` :ref:`[10] <spec_ref10>` :ref:`[11] <spec_ref11>`.
6565

6666
Spectre variant 1 (Bounds Check Bypass)
6767
---------------------------------------
@@ -131,6 +131,19 @@ steer its indirect branch speculations to gadget code, and measure the
131131
speculative execution's side effects left in level 1 cache to infer the
132132
victim's data.
133133

134+
Yet another variant 2 attack vector is for the attacker to poison the
135+
Branch History Buffer (BHB) to speculatively steer an indirect branch
136+
to a specific Branch Target Buffer (BTB) entry, even if the entry isn't
137+
associated with the source address of the indirect branch. Specifically,
138+
the BHB might be shared across privilege levels even in the presence of
139+
Enhanced IBRS.
140+
141+
Currently the only known real-world BHB attack vector is via
142+
unprivileged eBPF. Therefore, it's highly recommended to not enable
143+
unprivileged eBPF, especially when eIBRS is used (without retpolines).
144+
For a full mitigation against BHB attacks, it's recommended to use
145+
retpolines (or eIBRS combined with retpolines).
146+
134147
Attack scenarios
135148
----------------
136149

@@ -364,13 +377,15 @@ The possible values in this file are:
364377

365378
- Kernel status:
366379

367-
==================================== =================================
368-
'Not affected' The processor is not vulnerable
369-
'Vulnerable' Vulnerable, no mitigation
370-
'Mitigation: Full generic retpoline' Software-focused mitigation
371-
'Mitigation: Full AMD retpoline' AMD-specific software mitigation
372-
'Mitigation: Enhanced IBRS' Hardware-focused mitigation
373-
==================================== =================================
380+
======================================== =================================
381+
'Not affected' The processor is not vulnerable
382+
'Mitigation: None' Vulnerable, no mitigation
383+
'Mitigation: Retpolines' Use Retpoline thunks
384+
'Mitigation: LFENCE' Use LFENCE instructions
385+
'Mitigation: Enhanced IBRS' Hardware-focused mitigation
386+
'Mitigation: Enhanced IBRS + Retpolines' Hardware-focused + Retpolines
387+
'Mitigation: Enhanced IBRS + LFENCE' Hardware-focused + LFENCE
388+
======================================== =================================
374389

375390
- Firmware status: Show if Indirect Branch Restricted Speculation (IBRS) is
376391
used to protect against Spectre variant 2 attacks when calling firmware (x86 only).
@@ -583,12 +598,13 @@ kernel command line.
583598

584599
Specific mitigations can also be selected manually:
585600

586-
retpoline
587-
replace indirect branches
588-
retpoline,generic
589-
google's original retpoline
590-
retpoline,amd
591-
AMD-specific minimal thunk
601+
retpoline auto pick between generic,lfence
602+
retpoline,generic Retpolines
603+
retpoline,lfence LFENCE; indirect branch
604+
retpoline,amd alias for retpoline,lfence
605+
eibrs enhanced IBRS
606+
eibrs,retpoline enhanced IBRS + Retpolines
607+
eibrs,lfence enhanced IBRS + LFENCE
592608

593609
Not specifying this option is equivalent to
594610
spectre_v2=auto.
@@ -599,7 +615,7 @@ kernel command line.
599615
spectre_v2=off. Spectre variant 1 mitigations
600616
cannot be disabled.
601617

602-
For spectre_v2_user see :doc:`/admin-guide/kernel-parameters`.
618+
For spectre_v2_user see Documentation/admin-guide/kernel-parameters.txt
603619

604620
Mitigation selection guide
605621
--------------------------
@@ -681,7 +697,7 @@ AMD white papers:
681697

682698
.. _spec_ref6:
683699

684-
[6] `Software techniques for managing speculation on AMD processors <https://developer.amd.com/wp-content/resources/90343-B_SoftwareTechniquesforManagingSpeculation_WP_7-18Update_FNL.pdf>`_.
700+
[6] `Software techniques for managing speculation on AMD processors <https://developer.amd.com/wp-content/resources/Managing-Speculation-on-AMD-Processors.pdf>`_.
685701

686702
ARM white papers:
687703

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5361,8 +5361,12 @@
53615361
Specific mitigations can also be selected manually:
53625362

53635363
retpoline - replace indirect branches
5364-
retpoline,generic - google's original retpoline
5365-
retpoline,amd - AMD-specific minimal thunk
5364+
retpoline,generic - Retpolines
5365+
retpoline,lfence - LFENCE; indirect branch
5366+
retpoline,amd - alias for retpoline,lfence
5367+
eibrs - enhanced IBRS
5368+
eibrs,retpoline - enhanced IBRS + Retpolines
5369+
eibrs,lfence - enhanced IBRS + LFENCE
53665370

53675371
Not specifying this option is equivalent to
53685372
spectre_v2=auto.

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
/* FREE! ( 7*32+10) */
205205
#define X86_FEATURE_PTI ( 7*32+11) /* Kernel Page Table Isolation enabled */
206206
#define X86_FEATURE_RETPOLINE ( 7*32+12) /* "" Generic Retpoline mitigation for Spectre variant 2 */
207-
#define X86_FEATURE_RETPOLINE_AMD ( 7*32+13) /* "" AMD Retpoline mitigation for Spectre variant 2 */
207+
#define X86_FEATURE_RETPOLINE_LFENCE ( 7*32+13) /* "" Use LFENCE for Spectre variant 2 */
208208
#define X86_FEATURE_INTEL_PPIN ( 7*32+14) /* Intel Processor Inventory Number */
209209
#define X86_FEATURE_CDP_L2 ( 7*32+15) /* Code and Data Prioritization L2 */
210210
#define X86_FEATURE_MSR_SPEC_CTRL ( 7*32+16) /* "" MSR SPEC_CTRL is implemented */

arch/x86/include/asm/nospec-branch.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
#ifdef CONFIG_RETPOLINE
8585
ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \
8686
__stringify(jmp __x86_indirect_thunk_\reg), X86_FEATURE_RETPOLINE, \
87-
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), X86_FEATURE_RETPOLINE_AMD
87+
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), X86_FEATURE_RETPOLINE_LFENCE
8888
#else
8989
jmp *%\reg
9090
#endif
@@ -94,7 +94,7 @@
9494
#ifdef CONFIG_RETPOLINE
9595
ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; call *%\reg), \
9696
__stringify(call __x86_indirect_thunk_\reg), X86_FEATURE_RETPOLINE, \
97-
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; call *%\reg), X86_FEATURE_RETPOLINE_AMD
97+
__stringify(lfence; ANNOTATE_RETPOLINE_SAFE; call *%\reg), X86_FEATURE_RETPOLINE_LFENCE
9898
#else
9999
call *%\reg
100100
#endif
@@ -146,7 +146,7 @@ extern retpoline_thunk_t __x86_indirect_thunk_array[];
146146
"lfence;\n" \
147147
ANNOTATE_RETPOLINE_SAFE \
148148
"call *%[thunk_target]\n", \
149-
X86_FEATURE_RETPOLINE_AMD)
149+
X86_FEATURE_RETPOLINE_LFENCE)
150150

151151
# define THUNK_TARGET(addr) [thunk_target] "r" (addr)
152152

@@ -176,7 +176,7 @@ extern retpoline_thunk_t __x86_indirect_thunk_array[];
176176
"lfence;\n" \
177177
ANNOTATE_RETPOLINE_SAFE \
178178
"call *%[thunk_target]\n", \
179-
X86_FEATURE_RETPOLINE_AMD)
179+
X86_FEATURE_RETPOLINE_LFENCE)
180180

181181
# define THUNK_TARGET(addr) [thunk_target] "rm" (addr)
182182
#endif
@@ -188,9 +188,11 @@ extern retpoline_thunk_t __x86_indirect_thunk_array[];
188188
/* The Spectre V2 mitigation variants */
189189
enum spectre_v2_mitigation {
190190
SPECTRE_V2_NONE,
191-
SPECTRE_V2_RETPOLINE_GENERIC,
192-
SPECTRE_V2_RETPOLINE_AMD,
193-
SPECTRE_V2_IBRS_ENHANCED,
191+
SPECTRE_V2_RETPOLINE,
192+
SPECTRE_V2_LFENCE,
193+
SPECTRE_V2_EIBRS,
194+
SPECTRE_V2_EIBRS_RETPOLINE,
195+
SPECTRE_V2_EIBRS_LFENCE,
194196
};
195197

196198
/* The indirect branch speculation control variants */

arch/x86/kernel/alternative.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static int emit_indirect(int op, int reg, u8 *bytes)
389389
*
390390
* CALL *%\reg
391391
*
392-
* It also tries to inline spectre_v2=retpoline,amd when size permits.
392+
* It also tries to inline spectre_v2=retpoline,lfence when size permits.
393393
*/
394394
static int patch_retpoline(void *addr, struct insn *insn, u8 *bytes)
395395
{
@@ -407,7 +407,7 @@ static int patch_retpoline(void *addr, struct insn *insn, u8 *bytes)
407407
BUG_ON(reg == 4);
408408

409409
if (cpu_feature_enabled(X86_FEATURE_RETPOLINE) &&
410-
!cpu_feature_enabled(X86_FEATURE_RETPOLINE_AMD))
410+
!cpu_feature_enabled(X86_FEATURE_RETPOLINE_LFENCE))
411411
return -1;
412412

413413
op = insn->opcode.bytes[0];
@@ -438,9 +438,9 @@ static int patch_retpoline(void *addr, struct insn *insn, u8 *bytes)
438438
}
439439

440440
/*
441-
* For RETPOLINE_AMD: prepend the indirect CALL/JMP with an LFENCE.
441+
* For RETPOLINE_LFENCE: prepend the indirect CALL/JMP with an LFENCE.
442442
*/
443-
if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_AMD)) {
443+
if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_LFENCE)) {
444444
bytes[i++] = 0x0f;
445445
bytes[i++] = 0xae;
446446
bytes[i++] = 0xe8; /* LFENCE */

0 commit comments

Comments
 (0)