Skip to content

Commit 39c1614

Browse files
committed
Merge: x86/bugs: Support new SRSO CPUID bits for AMD ZEN 5 CPUs
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6779 JIRA: https://issues.redhat.com/browse/RHEL-88224 MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6779 Omitted-fix: af76f7d ("Documentation/x86: Update the naming of CPU features for /proc/cpuinfo") Omitted-fix: e120829 ("tools headers: Sync x86 kvm and cpufeature headers with the kernel") Omitted-fix: f6d9883 ("tools/include: Sync x86 headers with the kernel sources") Omitted-fix: 847f140 ("tools headers: Update the x86 headers with the kernel sources") The last 4 patches add support for the new SRSO_USER_KERNEL_NO and SRSO_MSR_FIX CPUID bits. The rests are additional patches to arch/x86/kernel/cpu/bugs.c to sync it up to v6.14 to ease future backport of x86 CPU vulnerability fixes. Note that QEMU hasn't yet supported the new new AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021. As a result, the required CPUID bits won't be passed down to the VM guest resulting in incorrect SRSO mitigation setting for Zen5 CPUs. Signed-off-by: Waiman Long <longman@redhat.com> Approved-by: Steve Best <sbest@redhat.com> Approved-by: Jay Shin <jaeshin@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Augusto Caringi <acaringi@redhat.com>
2 parents 7aefd61 + 19b33bf commit 39c1614

24 files changed

+963
-621
lines changed

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,20 @@ The possible values in this file are:
104104

105105
(spec_rstack_overflow=ibpb-vmexit)
106106

107+
* 'Mitigation: Reduced Speculation':
107108

109+
This mitigation gets automatically enabled when the above one "IBPB on
110+
VMEXIT" has been selected and the CPU supports the BpSpecReduce bit.
111+
112+
It gets automatically enabled on machines which have the
113+
SRSO_USER_KERNEL_NO=1 CPUID bit. In that case, the code logic is to switch
114+
to the above =ibpb-vmexit mitigation because the user/kernel boundary is
115+
not affected anymore and thus "safe RET" is not needed.
116+
117+
After enabling the IBPB on VMEXIT mitigation option, the BpSpecReduce bit
118+
is detected (functionality present on all such machines) and that
119+
practically overrides IBPB on VMEXIT as it has a lot less performance
120+
impact and takes care of the guest->host attack vector too.
108121

109122
In order to exploit vulnerability, an attacker needs to:
110123

@@ -158,3 +171,72 @@ poisoned BTB entry and using that safe one for all function returns.
158171
In older Zen1 and Zen2, this is accomplished using a reinterpretation
159172
technique similar to Retbleed one: srso_untrain_ret() and
160173
srso_safe_ret().
174+
175+
Checking the safe RET mitigation actually works
176+
-----------------------------------------------
177+
178+
In case one wants to validate whether the SRSO safe RET mitigation works
179+
on a kernel, one could use two performance counters
180+
181+
* PMC_0xc8 - Count of RET/RET lw retired
182+
* PMC_0xc9 - Count of RET/RET lw retired mispredicted
183+
184+
and compare the number of RETs retired properly vs those retired
185+
mispredicted, in kernel mode. Another way of specifying those events
186+
is::
187+
188+
# perf list ex_ret_near_ret
189+
190+
List of pre-defined events (to be used in -e or -M):
191+
192+
core:
193+
ex_ret_near_ret
194+
[Retired Near Returns]
195+
ex_ret_near_ret_mispred
196+
[Retired Near Returns Mispredicted]
197+
198+
Either the command using the event mnemonics::
199+
200+
# perf stat -e ex_ret_near_ret:k -e ex_ret_near_ret_mispred:k sleep 10s
201+
202+
or using the raw PMC numbers::
203+
204+
# perf stat -e cpu/event=0xc8,umask=0/k -e cpu/event=0xc9,umask=0/k sleep 10s
205+
206+
should give the same amount. I.e., every RET retired should be
207+
mispredicted::
208+
209+
[root@brent: ~/kernel/linux/tools/perf> ./perf stat -e cpu/event=0xc8,umask=0/k -e cpu/event=0xc9,umask=0/k sleep 10s
210+
211+
Performance counter stats for 'sleep 10s':
212+
213+
137,167 cpu/event=0xc8,umask=0/k
214+
137,173 cpu/event=0xc9,umask=0/k
215+
216+
10.004110303 seconds time elapsed
217+
218+
0.000000000 seconds user
219+
0.004462000 seconds sys
220+
221+
vs the case when the mitigation is disabled (spec_rstack_overflow=off)
222+
or not functioning properly, showing usually a lot smaller number of
223+
mispredicted retired RETs vs the overall count of retired RETs during
224+
a workload::
225+
226+
[root@brent: ~/kernel/linux/tools/perf> ./perf stat -e cpu/event=0xc8,umask=0/k -e cpu/event=0xc9,umask=0/k sleep 10s
227+
228+
Performance counter stats for 'sleep 10s':
229+
230+
201,627 cpu/event=0xc8,umask=0/k
231+
4,074 cpu/event=0xc9,umask=0/k
232+
233+
10.003267252 seconds time elapsed
234+
235+
0.002729000 seconds user
236+
0.000000000 seconds sys
237+
238+
Also, there is a selftest which performs the above, go to
239+
tools/testing/selftests/x86/ and do::
240+
241+
make srso
242+
./srso

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6020,9 +6020,15 @@
60206020
deployment of the HW BHI control and the SW BHB
60216021
clearing sequence.
60226022

6023-
on - (default) Enable the HW or SW mitigation
6024-
as needed.
6025-
off - Disable the mitigation.
6023+
on - (default) Enable the HW or SW mitigation as
6024+
needed. This protects the kernel from
6025+
both syscalls and VMs.
6026+
vmexit - On systems which don't have the HW mitigation
6027+
available, enable the SW mitigation on vmexit
6028+
ONLY. On such systems, the host kernel is
6029+
protected from VM-originated BHI attacks, but
6030+
may still be vulnerable to syscall attacks.
6031+
off - Disable the mitigation.
60266032

60276033
spectre_v2= [X86] Control mitigation of Spectre variant 2
60286034
(indirect branch speculation) vulnerability.

arch/x86/Kconfig

Lines changed: 110 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,7 +2572,8 @@ config MITIGATION_IBPB_ENTRY
25722572
depends on CPU_SUP_AMD && X86_64
25732573
default y
25742574
help
2575-
Compile the kernel with support for the retbleed=ibpb mitigation.
2575+
Compile the kernel with support for the retbleed=ibpb and
2576+
spec_rstack_overflow={ibpb,ibpb-vmexit} mitigations.
25762577

25772578
config MITIGATION_IBRS_ENTRY
25782579
bool "Enable IBRS on kernel entry"
@@ -2600,24 +2601,15 @@ config MITIGATION_SLS
26002601
against straight line speculation. The kernel image might be slightly
26012602
larger.
26022603

2603-
config MITIGATION_GDS_FORCE
2604-
bool "Force GDS Mitigation"
2604+
config MITIGATION_GDS
2605+
bool "Mitigate Gather Data Sampling"
26052606
depends on CPU_SUP_INTEL
2606-
default n
2607+
default y
26072608
help
2608-
Gather Data Sampling (GDS) is a hardware vulnerability which allows
2609-
unprivileged speculative access to data which was previously stored in
2610-
vector registers.
2611-
2612-
This option is equivalent to setting gather_data_sampling=force on the
2613-
command line. The microcode mitigation is used if present, otherwise
2614-
AVX is disabled as a mitigation. On affected systems that are missing
2615-
the microcode any userspace code that unconditionally uses AVX will
2616-
break with this option set.
2617-
2618-
Setting this option on systems not vulnerable to GDS has no effect.
2619-
2620-
If in doubt, say N.
2609+
Enable mitigation for Gather Data Sampling (GDS). GDS is a hardware
2610+
vulnerability which allows unprivileged speculative access to data
2611+
which was previously stored in vector registers. The attacker uses gather
2612+
instructions to infer the stale vector register data.
26212613

26222614
config MITIGATION_RFDS
26232615
bool "RFDS Mitigation"
@@ -2640,6 +2632,107 @@ config MITIGATION_SPECTRE_BHI
26402632
indirect branches.
26412633
See <file:Documentation/admin-guide/hw-vuln/spectre.rst>
26422634

2635+
config MITIGATION_MDS
2636+
bool "Mitigate Microarchitectural Data Sampling (MDS) hardware bug"
2637+
depends on CPU_SUP_INTEL
2638+
default y
2639+
help
2640+
Enable mitigation for Microarchitectural Data Sampling (MDS). MDS is
2641+
a hardware vulnerability which allows unprivileged speculative access
2642+
to data which is available in various CPU internal buffers.
2643+
See also <file:Documentation/admin-guide/hw-vuln/mds.rst>
2644+
2645+
config MITIGATION_TAA
2646+
bool "Mitigate TSX Asynchronous Abort (TAA) hardware bug"
2647+
depends on CPU_SUP_INTEL
2648+
default y
2649+
help
2650+
Enable mitigation for TSX Asynchronous Abort (TAA). TAA is a hardware
2651+
vulnerability that allows unprivileged speculative access to data
2652+
which is available in various CPU internal buffers by using
2653+
asynchronous aborts within an Intel TSX transactional region.
2654+
See also <file:Documentation/admin-guide/hw-vuln/tsx_async_abort.rst>
2655+
2656+
config MITIGATION_MMIO_STALE_DATA
2657+
bool "Mitigate MMIO Stale Data hardware bug"
2658+
depends on CPU_SUP_INTEL
2659+
default y
2660+
help
2661+
Enable mitigation for MMIO Stale Data hardware bugs. Processor MMIO
2662+
Stale Data Vulnerabilities are a class of memory-mapped I/O (MMIO)
2663+
vulnerabilities that can expose data. The vulnerabilities require the
2664+
attacker to have access to MMIO.
2665+
See also
2666+
<file:Documentation/admin-guide/hw-vuln/processor_mmio_stale_data.rst>
2667+
2668+
config MITIGATION_L1TF
2669+
bool "Mitigate L1 Terminal Fault (L1TF) hardware bug"
2670+
depends on CPU_SUP_INTEL
2671+
default y
2672+
help
2673+
Mitigate L1 Terminal Fault (L1TF) hardware bug. L1 Terminal Fault is a
2674+
hardware vulnerability which allows unprivileged speculative access to data
2675+
available in the Level 1 Data Cache.
2676+
See <file:Documentation/admin-guide/hw-vuln/l1tf.rst
2677+
2678+
config MITIGATION_RETBLEED
2679+
bool "Mitigate RETBleed hardware bug"
2680+
depends on (CPU_SUP_INTEL && MITIGATION_SPECTRE_V2) || MITIGATION_UNRET_ENTRY || MITIGATION_IBPB_ENTRY
2681+
default y
2682+
help
2683+
Enable mitigation for RETBleed (Arbitrary Speculative Code Execution
2684+
with Return Instructions) vulnerability. RETBleed is a speculative
2685+
execution attack which takes advantage of microarchitectural behavior
2686+
in many modern microprocessors, similar to Spectre v2. An
2687+
unprivileged attacker can use these flaws to bypass conventional
2688+
memory security restrictions to gain read access to privileged memory
2689+
that would otherwise be inaccessible.
2690+
2691+
config MITIGATION_SPECTRE_V1
2692+
bool "Mitigate SPECTRE V1 hardware bug"
2693+
default y
2694+
help
2695+
Enable mitigation for Spectre V1 (Bounds Check Bypass). Spectre V1 is a
2696+
class of side channel attacks that takes advantage of speculative
2697+
execution that bypasses conditional branch instructions used for
2698+
memory access bounds check.
2699+
See also <file:Documentation/admin-guide/hw-vuln/spectre.rst>
2700+
2701+
config MITIGATION_SPECTRE_V2
2702+
bool "Mitigate SPECTRE V2 hardware bug"
2703+
default y
2704+
help
2705+
Enable mitigation for Spectre V2 (Branch Target Injection). Spectre
2706+
V2 is a class of side channel attacks that takes advantage of
2707+
indirect branch predictors inside the processor. In Spectre variant 2
2708+
attacks, the attacker can steer speculative indirect branches in the
2709+
victim to gadget code by poisoning the branch target buffer of a CPU
2710+
used for predicting indirect branch addresses.
2711+
See also <file:Documentation/admin-guide/hw-vuln/spectre.rst>
2712+
2713+
config MITIGATION_SRBDS
2714+
bool "Mitigate Special Register Buffer Data Sampling (SRBDS) hardware bug"
2715+
depends on CPU_SUP_INTEL
2716+
default y
2717+
help
2718+
Enable mitigation for Special Register Buffer Data Sampling (SRBDS).
2719+
SRBDS is a hardware vulnerability that allows Microarchitectural Data
2720+
Sampling (MDS) techniques to infer values returned from special
2721+
register accesses. An unprivileged user can extract values returned
2722+
from RDRAND and RDSEED executed on another core or sibling thread
2723+
using MDS techniques.
2724+
See also
2725+
<file:Documentation/admin-guide/hw-vuln/special-register-buffer-data-sampling.rst>
2726+
2727+
config MITIGATION_SSB
2728+
bool "Mitigate Speculative Store Bypass (SSB) hardware bug"
2729+
default y
2730+
help
2731+
Enable mitigation for Speculative Store Bypass (SSB). SSB is a
2732+
hardware security vulnerability and its exploitation takes advantage
2733+
of speculative execution in a similar way to the Meltdown and Spectre
2734+
security vulnerabilities.
2735+
26432736
endif
26442737

26452738
config ARCH_HAS_ADD_PAGES

0 commit comments

Comments
 (0)