Skip to content

Commit 8b4d37d

Browse files
committed
Merge branch 'x86/srbds' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 srbds fixes from Thomas Gleixner: "The 9th episode of the dime novel "The performance killer" with the subtitle "Slow Randomizing Boosts Denial of Service". SRBDS is an MDS-like speculative side channel that can leak bits from the random number generator (RNG) across cores and threads. New microcode serializes the processor access during the execution of RDRAND and RDSEED. This ensures that the shared buffer is overwritten before it is released for reuse. This is equivalent to a full bus lock, which means that many threads running the RNG instructions in parallel have the same effect as the same amount of threads issuing a locked instruction targeting an address which requires locking of two cachelines at once. The mitigation support comes with the usual pile of unpleasant ingredients: - command line options - sysfs file - microcode checks - a list of vulnerable CPUs identified by model and stepping this time which requires stepping match support for the cpu match logic. - the inevitable slowdown of affected CPUs" * branch 'x86/srbds' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/speculation: Add Ivy Bridge to affected list x86/speculation: Add SRBDS vulnerability and mitigation documentation x86/speculation: Add Special Register Buffer Data Sampling (SRBDS) mitigation x86/cpu: Add 'table' argument to cpu_matches()
2 parents abfbb29 + 3798cc4 commit 8b4d37d

File tree

10 files changed

+337
-11
lines changed

10 files changed

+337
-11
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ What: /sys/devices/system/cpu/vulnerabilities
486486
/sys/devices/system/cpu/vulnerabilities/spec_store_bypass
487487
/sys/devices/system/cpu/vulnerabilities/l1tf
488488
/sys/devices/system/cpu/vulnerabilities/mds
489+
/sys/devices/system/cpu/vulnerabilities/srbds
489490
/sys/devices/system/cpu/vulnerabilities/tsx_async_abort
490491
/sys/devices/system/cpu/vulnerabilities/itlb_multihit
491492
Date: January 2018

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ are configurable at compile, boot or run time.
1414
mds
1515
tsx_async_abort
1616
multihit.rst
17+
special-register-buffer-data-sampling.rst
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
SRBDS - Special Register Buffer Data Sampling
4+
=============================================
5+
6+
SRBDS is a hardware vulnerability that allows MDS :doc:`mds` techniques to
7+
infer values returned from special register accesses. Special register
8+
accesses are accesses to off core registers. According to Intel's evaluation,
9+
the special register reads that have a security expectation of privacy are
10+
RDRAND, RDSEED and SGX EGETKEY.
11+
12+
When RDRAND, RDSEED and EGETKEY instructions are used, the data is moved
13+
to the core through the special register mechanism that is susceptible
14+
to MDS attacks.
15+
16+
Affected processors
17+
--------------------
18+
Core models (desktop, mobile, Xeon-E3) that implement RDRAND and/or RDSEED may
19+
be affected.
20+
21+
A processor is affected by SRBDS if its Family_Model and stepping is
22+
in the following list, with the exception of the listed processors
23+
exporting MDS_NO while Intel TSX is available yet not enabled. The
24+
latter class of processors are only affected when Intel TSX is enabled
25+
by software using TSX_CTRL_MSR otherwise they are not affected.
26+
27+
============= ============ ========
28+
common name Family_Model Stepping
29+
============= ============ ========
30+
IvyBridge 06_3AH All
31+
32+
Haswell 06_3CH All
33+
Haswell_L 06_45H All
34+
Haswell_G 06_46H All
35+
36+
Broadwell_G 06_47H All
37+
Broadwell 06_3DH All
38+
39+
Skylake_L 06_4EH All
40+
Skylake 06_5EH All
41+
42+
Kabylake_L 06_8EH <= 0xC
43+
Kabylake 06_9EH <= 0xD
44+
============= ============ ========
45+
46+
Related CVEs
47+
------------
48+
49+
The following CVE entry is related to this SRBDS issue:
50+
51+
============== ===== =====================================
52+
CVE-2020-0543 SRBDS Special Register Buffer Data Sampling
53+
============== ===== =====================================
54+
55+
Attack scenarios
56+
----------------
57+
An unprivileged user can extract values returned from RDRAND and RDSEED
58+
executed on another core or sibling thread using MDS techniques.
59+
60+
61+
Mitigation mechanism
62+
-------------------
63+
Intel will release microcode updates that modify the RDRAND, RDSEED, and
64+
EGETKEY instructions to overwrite secret special register data in the shared
65+
staging buffer before the secret data can be accessed by another logical
66+
processor.
67+
68+
During execution of the RDRAND, RDSEED, or EGETKEY instructions, off-core
69+
accesses from other logical processors will be delayed until the special
70+
register read is complete and the secret data in the shared staging buffer is
71+
overwritten.
72+
73+
This has three effects on performance:
74+
75+
#. RDRAND, RDSEED, or EGETKEY instructions have higher latency.
76+
77+
#. Executing RDRAND at the same time on multiple logical processors will be
78+
serialized, resulting in an overall reduction in the maximum RDRAND
79+
bandwidth.
80+
81+
#. Executing RDRAND, RDSEED or EGETKEY will delay memory accesses from other
82+
logical processors that miss their core caches, with an impact similar to
83+
legacy locked cache-line-split accesses.
84+
85+
The microcode updates provide an opt-out mechanism (RNGDS_MITG_DIS) to disable
86+
the mitigation for RDRAND and RDSEED instructions executed outside of Intel
87+
Software Guard Extensions (Intel SGX) enclaves. On logical processors that
88+
disable the mitigation using this opt-out mechanism, RDRAND and RDSEED do not
89+
take longer to execute and do not impact performance of sibling logical
90+
processors memory accesses. The opt-out mechanism does not affect Intel SGX
91+
enclaves (including execution of RDRAND or RDSEED inside an enclave, as well
92+
as EGETKEY execution).
93+
94+
IA32_MCU_OPT_CTRL MSR Definition
95+
--------------------------------
96+
Along with the mitigation for this issue, Intel added a new thread-scope
97+
IA32_MCU_OPT_CTRL MSR, (address 0x123). The presence of this MSR and
98+
RNGDS_MITG_DIS (bit 0) is enumerated by CPUID.(EAX=07H,ECX=0).EDX[SRBDS_CTRL =
99+
9]==1. This MSR is introduced through the microcode update.
100+
101+
Setting IA32_MCU_OPT_CTRL[0] (RNGDS_MITG_DIS) to 1 for a logical processor
102+
disables the mitigation for RDRAND and RDSEED executed outside of an Intel SGX
103+
enclave on that logical processor. Opting out of the mitigation for a
104+
particular logical processor does not affect the RDRAND and RDSEED mitigations
105+
for other logical processors.
106+
107+
Note that inside of an Intel SGX enclave, the mitigation is applied regardless
108+
of the value of RNGDS_MITG_DS.
109+
110+
Mitigation control on the kernel command line
111+
---------------------------------------------
112+
The kernel command line allows control over the SRBDS mitigation at boot time
113+
with the option "srbds=". The option for this is:
114+
115+
============= =============================================================
116+
off This option disables SRBDS mitigation for RDRAND and RDSEED on
117+
affected platforms.
118+
============= =============================================================
119+
120+
SRBDS System Information
121+
-----------------------
122+
The Linux kernel provides vulnerability status information through sysfs. For
123+
SRBDS this can be accessed by the following sysfs file:
124+
/sys/devices/system/cpu/vulnerabilities/srbds
125+
126+
The possible values contained in this file are:
127+
128+
============================== =============================================
129+
Not affected Processor not vulnerable
130+
Vulnerable Processor vulnerable and mitigation disabled
131+
Vulnerable: No microcode Processor vulnerable and microcode is missing
132+
mitigation
133+
Mitigation: Microcode Processor is vulnerable and mitigation is in
134+
effect.
135+
Mitigation: TSX disabled Processor is only vulnerable when TSX is
136+
enabled while this system was booted with TSX
137+
disabled.
138+
Unknown: Dependent on
139+
hypervisor status Running on virtual guest processor that is
140+
affected but with no way to know if host
141+
processor is mitigated or vulnerable.
142+
============================== =============================================
143+
144+
SRBDS Default mitigation
145+
------------------------
146+
This new microcode serializes processor access during execution of RDRAND,
147+
RDSEED ensures that the shared buffer is overwritten before it is released for
148+
reuse. Use the "srbds=off" kernel command line to disable the mitigation for
149+
RDRAND and RDSEED.

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4837,6 +4837,26 @@
48374837
the kernel will oops in either "warn" or "fatal"
48384838
mode.
48394839

4840+
srbds= [X86,INTEL]
4841+
Control the Special Register Buffer Data Sampling
4842+
(SRBDS) mitigation.
4843+
4844+
Certain CPUs are vulnerable to an MDS-like
4845+
exploit which can leak bits from the random
4846+
number generator.
4847+
4848+
By default, this issue is mitigated by
4849+
microcode. However, the microcode fix can cause
4850+
the RDRAND and RDSEED instructions to become
4851+
much slower. Among other effects, this will
4852+
result in reduced throughput from /dev/urandom.
4853+
4854+
The microcode mitigation can be disabled with
4855+
the following option:
4856+
4857+
off: Disable mitigation and remove
4858+
performance impact to RDRAND and RDSEED
4859+
48404860
srcutree.counter_wrap_check [KNL]
48414861
Specifies how frequently to check for
48424862
grace-period sequence counter wrap for the

arch/x86/include/asm/cpufeatures.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@
362362
#define X86_FEATURE_AVX512_4FMAPS (18*32+ 3) /* AVX-512 Multiply Accumulation Single precision */
363363
#define X86_FEATURE_FSRM (18*32+ 4) /* Fast Short Rep Mov */
364364
#define X86_FEATURE_AVX512_VP2INTERSECT (18*32+ 8) /* AVX-512 Intersect for D/Q */
365+
#define X86_FEATURE_SRBDS_CTRL (18*32+ 9) /* "" SRBDS mitigation MSR available */
365366
#define X86_FEATURE_MD_CLEAR (18*32+10) /* VERW clears CPU buffers */
366367
#define X86_FEATURE_TSX_FORCE_ABORT (18*32+13) /* "" TSX_FORCE_ABORT */
367368
#define X86_FEATURE_PCONFIG (18*32+18) /* Intel PCONFIG */
@@ -407,5 +408,6 @@
407408
#define X86_BUG_SWAPGS X86_BUG(21) /* CPU is affected by speculation through SWAPGS */
408409
#define X86_BUG_TAA X86_BUG(22) /* CPU is affected by TSX Async Abort(TAA) */
409410
#define X86_BUG_ITLB_MULTIHIT X86_BUG(23) /* CPU may incur MCE during certain page attribute changes */
411+
#define X86_BUG_SRBDS X86_BUG(24) /* CPU may leak RNG bits if not mitigated */
410412

411413
#endif /* _ASM_X86_CPUFEATURES_H */

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@
128128
#define TSX_CTRL_RTM_DISABLE BIT(0) /* Disable RTM feature */
129129
#define TSX_CTRL_CPUID_CLEAR BIT(1) /* Disable TSX enumeration */
130130

131+
/* SRBDS support */
132+
#define MSR_IA32_MCU_OPT_CTRL 0x00000123
133+
#define RNGDS_MITG_DIS BIT(0)
134+
131135
#define MSR_IA32_SYSENTER_CS 0x00000174
132136
#define MSR_IA32_SYSENTER_ESP 0x00000175
133137
#define MSR_IA32_SYSENTER_EIP 0x00000176

arch/x86/kernel/cpu/bugs.c

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static void __init l1tf_select_mitigation(void);
4141
static void __init mds_select_mitigation(void);
4242
static void __init mds_print_mitigation(void);
4343
static void __init taa_select_mitigation(void);
44+
static void __init srbds_select_mitigation(void);
4445

4546
/* The base value of the SPEC_CTRL MSR that always has to be preserved. */
4647
u64 x86_spec_ctrl_base;
@@ -108,6 +109,7 @@ void __init check_bugs(void)
108109
l1tf_select_mitigation();
109110
mds_select_mitigation();
110111
taa_select_mitigation();
112+
srbds_select_mitigation();
111113

112114
/*
113115
* As MDS and TAA mitigations are inter-related, print MDS
@@ -397,6 +399,97 @@ static int __init tsx_async_abort_parse_cmdline(char *str)
397399
}
398400
early_param("tsx_async_abort", tsx_async_abort_parse_cmdline);
399401

402+
#undef pr_fmt
403+
#define pr_fmt(fmt) "SRBDS: " fmt
404+
405+
enum srbds_mitigations {
406+
SRBDS_MITIGATION_OFF,
407+
SRBDS_MITIGATION_UCODE_NEEDED,
408+
SRBDS_MITIGATION_FULL,
409+
SRBDS_MITIGATION_TSX_OFF,
410+
SRBDS_MITIGATION_HYPERVISOR,
411+
};
412+
413+
static enum srbds_mitigations srbds_mitigation __ro_after_init = SRBDS_MITIGATION_FULL;
414+
415+
static const char * const srbds_strings[] = {
416+
[SRBDS_MITIGATION_OFF] = "Vulnerable",
417+
[SRBDS_MITIGATION_UCODE_NEEDED] = "Vulnerable: No microcode",
418+
[SRBDS_MITIGATION_FULL] = "Mitigation: Microcode",
419+
[SRBDS_MITIGATION_TSX_OFF] = "Mitigation: TSX disabled",
420+
[SRBDS_MITIGATION_HYPERVISOR] = "Unknown: Dependent on hypervisor status",
421+
};
422+
423+
static bool srbds_off;
424+
425+
void update_srbds_msr(void)
426+
{
427+
u64 mcu_ctrl;
428+
429+
if (!boot_cpu_has_bug(X86_BUG_SRBDS))
430+
return;
431+
432+
if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
433+
return;
434+
435+
if (srbds_mitigation == SRBDS_MITIGATION_UCODE_NEEDED)
436+
return;
437+
438+
rdmsrl(MSR_IA32_MCU_OPT_CTRL, mcu_ctrl);
439+
440+
switch (srbds_mitigation) {
441+
case SRBDS_MITIGATION_OFF:
442+
case SRBDS_MITIGATION_TSX_OFF:
443+
mcu_ctrl |= RNGDS_MITG_DIS;
444+
break;
445+
case SRBDS_MITIGATION_FULL:
446+
mcu_ctrl &= ~RNGDS_MITG_DIS;
447+
break;
448+
default:
449+
break;
450+
}
451+
452+
wrmsrl(MSR_IA32_MCU_OPT_CTRL, mcu_ctrl);
453+
}
454+
455+
static void __init srbds_select_mitigation(void)
456+
{
457+
u64 ia32_cap;
458+
459+
if (!boot_cpu_has_bug(X86_BUG_SRBDS))
460+
return;
461+
462+
/*
463+
* Check to see if this is one of the MDS_NO systems supporting
464+
* TSX that are only exposed to SRBDS when TSX is enabled.
465+
*/
466+
ia32_cap = x86_read_arch_cap_msr();
467+
if ((ia32_cap & ARCH_CAP_MDS_NO) && !boot_cpu_has(X86_FEATURE_RTM))
468+
srbds_mitigation = SRBDS_MITIGATION_TSX_OFF;
469+
else if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
470+
srbds_mitigation = SRBDS_MITIGATION_HYPERVISOR;
471+
else if (!boot_cpu_has(X86_FEATURE_SRBDS_CTRL))
472+
srbds_mitigation = SRBDS_MITIGATION_UCODE_NEEDED;
473+
else if (cpu_mitigations_off() || srbds_off)
474+
srbds_mitigation = SRBDS_MITIGATION_OFF;
475+
476+
update_srbds_msr();
477+
pr_info("%s\n", srbds_strings[srbds_mitigation]);
478+
}
479+
480+
static int __init srbds_parse_cmdline(char *str)
481+
{
482+
if (!str)
483+
return -EINVAL;
484+
485+
if (!boot_cpu_has_bug(X86_BUG_SRBDS))
486+
return 0;
487+
488+
srbds_off = !strcmp(str, "off");
489+
return 0;
490+
}
491+
early_param("srbds", srbds_parse_cmdline);
492+
400493
#undef pr_fmt
401494
#define pr_fmt(fmt) "Spectre V1 : " fmt
402495

@@ -1528,6 +1621,11 @@ static char *ibpb_state(void)
15281621
return "";
15291622
}
15301623

1624+
static ssize_t srbds_show_state(char *buf)
1625+
{
1626+
return sprintf(buf, "%s\n", srbds_strings[srbds_mitigation]);
1627+
}
1628+
15311629
static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,
15321630
char *buf, unsigned int bug)
15331631
{
@@ -1572,6 +1670,9 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr
15721670
case X86_BUG_ITLB_MULTIHIT:
15731671
return itlb_multihit_show_state(buf);
15741672

1673+
case X86_BUG_SRBDS:
1674+
return srbds_show_state(buf);
1675+
15751676
default:
15761677
break;
15771678
}
@@ -1618,4 +1719,9 @@ ssize_t cpu_show_itlb_multihit(struct device *dev, struct device_attribute *attr
16181719
{
16191720
return cpu_show_common(dev, attr, buf, X86_BUG_ITLB_MULTIHIT);
16201721
}
1722+
1723+
ssize_t cpu_show_srbds(struct device *dev, struct device_attribute *attr, char *buf)
1724+
{
1725+
return cpu_show_common(dev, attr, buf, X86_BUG_SRBDS);
1726+
}
16211727
#endif

0 commit comments

Comments
 (0)