Skip to content

Commit 6f5bf94

Browse files
committed
Merge tag 'its-for-linus-20250509' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 ITS mitigation from Dave Hansen: "Mitigate Indirect Target Selection (ITS) issue. I'd describe this one as a good old CPU bug where the behavior is _obviously_ wrong, but since it just results in bad predictions it wasn't wrong enough to notice. Well, the researchers noticed and also realized that thus bug undermined a bunch of existing indirect branch mitigations. Thus the unusually wide impact on this one. Details: ITS is a bug in some Intel CPUs that affects indirect branches including RETs in the first half of a cacheline. Due to ITS such branches may get wrongly predicted to a target of (direct or indirect) branch that is located in the second half of a cacheline. Researchers at VUSec found this behavior and reported to Intel. Affected processors: - Cascade Lake, Cooper Lake, Whiskey Lake V, Coffee Lake R, Comet Lake, Ice Lake, Tiger Lake and Rocket Lake. Scope of impact: - Guest/host isolation: When eIBRS is used for guest/host isolation, the indirect branches in the VMM may still be predicted with targets corresponding to direct branches in the guest. - Intra-mode using cBPF: cBPF can be used to poison the branch history to exploit ITS. Realigning the indirect branches and RETs mitigates this attack vector. - User/kernel: With eIBRS enabled user/kernel isolation is *not* impacted by ITS. - Indirect Branch Prediction Barrier (IBPB): Due to this bug indirect branches may be predicted with targets corresponding to direct branches which were executed prior to IBPB. This will be fixed in the microcode. Mitigation: As indirect branches in the first half of cacheline are affected, the mitigation is to replace those indirect branches with a call to thunk that is aligned to the second half of the cacheline. RETs that take prediction from RSB are not affected, but they may be affected by RSB-underflow condition. So, RETs in the first half of cacheline are also patched to a return thunk that executes the RET aligned to second half of cacheline" * tag 'its-for-linus-20250509' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: selftest/x86/bugs: Add selftests for ITS x86/its: FineIBT-paranoid vs ITS x86/its: Use dynamic thunks for indirect branches x86/ibt: Keep IBT disabled during alternative patching mm/execmem: Unify early execmem_cache behaviour x86/its: Align RETs in BHB clear sequence to avoid thunking x86/its: Add support for RSB stuffing mitigation x86/its: Add "vmexit" option to skip mitigation on some CPUs x86/its: Enable Indirect Target Selection mitigation x86/its: Add support for ITS-safe return thunk x86/its: Add support for ITS-safe indirect thunk x86/its: Enumerate Indirect Target Selection (ITS) bug Documentation: x86/bugs/its: Add ITS documentation
2 parents caf12fa + 7a9b709 commit 6f5bf94

35 files changed

+1581
-49
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ Description: information about CPUs heterogeneity.
511511

512512
What: /sys/devices/system/cpu/vulnerabilities
513513
/sys/devices/system/cpu/vulnerabilities/gather_data_sampling
514+
/sys/devices/system/cpu/vulnerabilities/indirect_target_selection
514515
/sys/devices/system/cpu/vulnerabilities/itlb_multihit
515516
/sys/devices/system/cpu/vulnerabilities/l1tf
516517
/sys/devices/system/cpu/vulnerabilities/mds

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ are configurable at compile, boot or run time.
2323
gather_data_sampling
2424
reg-file-data-sampling
2525
rsb
26+
indirect-target-selection
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
Indirect Target Selection (ITS)
4+
===============================
5+
6+
ITS is a vulnerability in some Intel CPUs that support Enhanced IBRS and were
7+
released before Alder Lake. ITS may allow an attacker to control the prediction
8+
of indirect branches and RETs located in the lower half of a cacheline.
9+
10+
ITS is assigned CVE-2024-28956 with a CVSS score of 4.7 (Medium).
11+
12+
Scope of Impact
13+
---------------
14+
- **eIBRS Guest/Host Isolation**: Indirect branches in KVM/kernel may still be
15+
predicted with unintended target corresponding to a branch in the guest.
16+
17+
- **Intra-Mode BTI**: In-kernel training such as through cBPF or other native
18+
gadgets.
19+
20+
- **Indirect Branch Prediction Barrier (IBPB)**: After an IBPB, indirect
21+
branches may still be predicted with targets corresponding to direct branches
22+
executed prior to the IBPB. This is fixed by the IPU 2025.1 microcode, which
23+
should be available via distro updates. Alternatively microcode can be
24+
obtained from Intel's github repository [#f1]_.
25+
26+
Affected CPUs
27+
-------------
28+
Below is the list of ITS affected CPUs [#f2]_ [#f3]_:
29+
30+
======================== ============ ==================== ===============
31+
Common name Family_Model eIBRS Intra-mode BTI
32+
Guest/Host Isolation
33+
======================== ============ ==================== ===============
34+
SKYLAKE_X (step >= 6) 06_55H Affected Affected
35+
ICELAKE_X 06_6AH Not affected Affected
36+
ICELAKE_D 06_6CH Not affected Affected
37+
ICELAKE_L 06_7EH Not affected Affected
38+
TIGERLAKE_L 06_8CH Not affected Affected
39+
TIGERLAKE 06_8DH Not affected Affected
40+
KABYLAKE_L (step >= 12) 06_8EH Affected Affected
41+
KABYLAKE (step >= 13) 06_9EH Affected Affected
42+
COMETLAKE 06_A5H Affected Affected
43+
COMETLAKE_L 06_A6H Affected Affected
44+
ROCKETLAKE 06_A7H Not affected Affected
45+
======================== ============ ==================== ===============
46+
47+
- All affected CPUs enumerate Enhanced IBRS feature.
48+
- IBPB isolation is affected on all ITS affected CPUs, and need a microcode
49+
update for mitigation.
50+
- None of the affected CPUs enumerate BHI_CTRL which was introduced in Golden
51+
Cove (Alder Lake and Sapphire Rapids). This can help guests to determine the
52+
host's affected status.
53+
- Intel Atom CPUs are not affected by ITS.
54+
55+
Mitigation
56+
----------
57+
As only the indirect branches and RETs that have their last byte of instruction
58+
in the lower half of the cacheline are vulnerable to ITS, the basic idea behind
59+
the mitigation is to not allow indirect branches in the lower half.
60+
61+
This is achieved by relying on existing retpoline support in the kernel, and in
62+
compilers. ITS-vulnerable retpoline sites are runtime patched to point to newly
63+
added ITS-safe thunks. These safe thunks consists of indirect branch in the
64+
second half of the cacheline. Not all retpoline sites are patched to thunks, if
65+
a retpoline site is evaluated to be ITS-safe, it is replaced with an inline
66+
indirect branch.
67+
68+
Dynamic thunks
69+
~~~~~~~~~~~~~~
70+
From a dynamically allocated pool of safe-thunks, each vulnerable site is
71+
replaced with a new thunk, such that they get a unique address. This could
72+
improve the branch prediction accuracy. Also, it is a defense-in-depth measure
73+
against aliasing.
74+
75+
Note, for simplicity, indirect branches in eBPF programs are always replaced
76+
with a jump to a static thunk in __x86_indirect_its_thunk_array. If required,
77+
in future this can be changed to use dynamic thunks.
78+
79+
All vulnerable RETs are replaced with a static thunk, they do not use dynamic
80+
thunks. This is because RETs get their prediction from RSB mostly that does not
81+
depend on source address. RETs that underflow RSB may benefit from dynamic
82+
thunks. But, RETs significantly outnumber indirect branches, and any benefit
83+
from a unique source address could be outweighed by the increased icache
84+
footprint and iTLB pressure.
85+
86+
Retpoline
87+
~~~~~~~~~
88+
Retpoline sequence also mitigates ITS-unsafe indirect branches. For this
89+
reason, when retpoline is enabled, ITS mitigation only relocates the RETs to
90+
safe thunks. Unless user requested the RSB-stuffing mitigation.
91+
92+
RSB Stuffing
93+
~~~~~~~~~~~~
94+
RSB-stuffing via Call Depth Tracking is a mitigation for Retbleed RSB-underflow
95+
attacks. And it also mitigates RETs that are vulnerable to ITS.
96+
97+
Mitigation in guests
98+
^^^^^^^^^^^^^^^^^^^^
99+
All guests deploy ITS mitigation by default, irrespective of eIBRS enumeration
100+
and Family/Model of the guest. This is because eIBRS feature could be hidden
101+
from a guest. One exception to this is when a guest enumerates BHI_DIS_S, which
102+
indicates that the guest is running on an unaffected host.
103+
104+
To prevent guests from unnecessarily deploying the mitigation on unaffected
105+
platforms, Intel has defined ITS_NO bit(62) in MSR IA32_ARCH_CAPABILITIES. When
106+
a guest sees this bit set, it should not enumerate the ITS bug. Note, this bit
107+
is not set by any hardware, but is **intended for VMMs to synthesize** it for
108+
guests as per the host's affected status.
109+
110+
Mitigation options
111+
^^^^^^^^^^^^^^^^^^
112+
The ITS mitigation can be controlled using the "indirect_target_selection"
113+
kernel parameter. The available options are:
114+
115+
======== ===================================================================
116+
on (default) Deploy the "Aligned branch/return thunks" mitigation.
117+
If spectre_v2 mitigation enables retpoline, aligned-thunks are only
118+
deployed for the affected RET instructions. Retpoline mitigates
119+
indirect branches.
120+
121+
off Disable ITS mitigation.
122+
123+
vmexit Equivalent to "=on" if the CPU is affected by guest/host isolation
124+
part of ITS. Otherwise, mitigation is not deployed. This option is
125+
useful when host userspace is not in the threat model, and only
126+
attacks from guest to host are considered.
127+
128+
stuff Deploy RSB-fill mitigation when retpoline is also deployed.
129+
Otherwise, deploy the default mitigation. When retpoline mitigation
130+
is enabled, RSB-stuffing via Call-Depth-Tracking also mitigates
131+
ITS.
132+
133+
force Force the ITS bug and deploy the default mitigation.
134+
======== ===================================================================
135+
136+
Sysfs reporting
137+
---------------
138+
139+
The sysfs file showing ITS mitigation status is:
140+
141+
/sys/devices/system/cpu/vulnerabilities/indirect_target_selection
142+
143+
Note, microcode mitigation status is not reported in this file.
144+
145+
The possible values in this file are:
146+
147+
.. list-table::
148+
149+
* - Not affected
150+
- The processor is not vulnerable.
151+
* - Vulnerable
152+
- System is vulnerable and no mitigation has been applied.
153+
* - Vulnerable, KVM: Not affected
154+
- System is vulnerable to intra-mode BTI, but not affected by eIBRS
155+
guest/host isolation.
156+
* - Mitigation: Aligned branch/return thunks
157+
- The mitigation is enabled, affected indirect branches and RETs are
158+
relocated to safe thunks.
159+
* - Mitigation: Retpolines, Stuffing RSB
160+
- The mitigation is enabled using retpoline and RSB stuffing.
161+
162+
References
163+
----------
164+
.. [#f1] Microcode repository - https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files
165+
166+
.. [#f2] Affected Processors list - https://www.intel.com/content/www/us/en/developer/topic-technology/software-security-guidance/processors-affected-consolidated-product-cpu-model.html
167+
168+
.. [#f3] Affected Processors list (machine readable) - https://github.com/intel/Intel-affected-processor-list

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,6 +2202,23 @@
22022202
different crypto accelerators. This option can be used
22032203
to achieve best performance for particular HW.
22042204

2205+
indirect_target_selection= [X86,Intel] Mitigation control for Indirect
2206+
Target Selection(ITS) bug in Intel CPUs. Updated
2207+
microcode is also required for a fix in IBPB.
2208+
2209+
on: Enable mitigation (default).
2210+
off: Disable mitigation.
2211+
force: Force the ITS bug and deploy default
2212+
mitigation.
2213+
vmexit: Only deploy mitigation if CPU is affected by
2214+
guest/host isolation part of ITS.
2215+
stuff: Deploy RSB-fill mitigation when retpoline is
2216+
also deployed. Otherwise, deploy the default
2217+
mitigation.
2218+
2219+
For details see:
2220+
Documentation/admin-guide/hw-vuln/indirect-target-selection.rst
2221+
22052222
init= [KNL]
22062223
Format: <full_path>
22072224
Run specified binary instead of /sbin/init as init
@@ -3693,6 +3710,7 @@
36933710
expose users to several CPU vulnerabilities.
36943711
Equivalent to: if nokaslr then kpti=0 [ARM64]
36953712
gather_data_sampling=off [X86]
3713+
indirect_target_selection=off [X86]
36963714
kvm.nx_huge_pages=off [X86]
36973715
l1tf=off [X86]
36983716
mds=off [X86]

arch/x86/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,6 +2711,18 @@ config MITIGATION_SSB
27112711
of speculative execution in a similar way to the Meltdown and Spectre
27122712
security vulnerabilities.
27132713

2714+
config MITIGATION_ITS
2715+
bool "Enable Indirect Target Selection mitigation"
2716+
depends on CPU_SUP_INTEL && X86_64
2717+
depends on MITIGATION_RETPOLINE && MITIGATION_RETHUNK
2718+
select EXECMEM
2719+
default y
2720+
help
2721+
Enable Indirect Target Selection (ITS) mitigation. ITS is a bug in
2722+
BPU on some Intel CPUs that may allow Spectre V2 style attacks. If
2723+
disabled, mitigation cannot be enabled via cmdline.
2724+
See <file:Documentation/admin-guide/hw-vuln/indirect-target-selection.rst>
2725+
27142726
endif
27152727

27162728
config ARCH_HAS_ADD_PAGES

arch/x86/entry/entry_64.S

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,9 @@ SYM_CODE_END(rewind_stack_and_make_dead)
15251525
* ORC to unwind properly.
15261526
*
15271527
* The alignment is for performance and not for safety, and may be safely
1528-
* refactored in the future if needed.
1528+
* refactored in the future if needed. The .skips are for safety, to ensure
1529+
* that all RETs are in the second half of a cacheline to mitigate Indirect
1530+
* Target Selection, rather than taking the slowpath via its_return_thunk.
15291531
*/
15301532
SYM_FUNC_START(clear_bhb_loop)
15311533
ANNOTATE_NOENDBR
@@ -1536,18 +1538,30 @@ SYM_FUNC_START(clear_bhb_loop)
15361538
call 1f
15371539
jmp 5f
15381540
.align 64, 0xcc
1541+
/*
1542+
* Shift instructions so that the RET is in the upper half of the
1543+
* cacheline and don't take the slowpath to its_return_thunk.
1544+
*/
1545+
.skip 32 - (.Lret1 - 1f), 0xcc
15391546
ANNOTATE_INTRA_FUNCTION_CALL
15401547
1: call 2f
1541-
RET
1548+
.Lret1: RET
15421549
.align 64, 0xcc
1550+
/*
1551+
* As above shift instructions for RET at .Lret2 as well.
1552+
*
1553+
* This should be ideally be: .skip 32 - (.Lret2 - 2f), 0xcc
1554+
* but some Clang versions (e.g. 18) don't like this.
1555+
*/
1556+
.skip 32 - 18, 0xcc
15431557
2: movl $5, %eax
15441558
3: jmp 4f
15451559
nop
15461560
4: sub $1, %eax
15471561
jnz 3b
15481562
sub $1, %ecx
15491563
jnz 1b
1550-
RET
1564+
.Lret2: RET
15511565
5: lfence
15521566
pop %rbp
15531567
RET

arch/x86/include/asm/alternative.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/stringify.h>
77
#include <linux/objtool.h>
88
#include <asm/asm.h>
9+
#include <asm/bug.h>
910

1011
#define ALT_FLAGS_SHIFT 16
1112

@@ -124,6 +125,37 @@ static __always_inline int x86_call_depth_emit_accounting(u8 **pprog,
124125
}
125126
#endif
126127

128+
#ifdef CONFIG_MITIGATION_ITS
129+
extern void its_init_mod(struct module *mod);
130+
extern void its_fini_mod(struct module *mod);
131+
extern void its_free_mod(struct module *mod);
132+
extern u8 *its_static_thunk(int reg);
133+
#else /* CONFIG_MITIGATION_ITS */
134+
static inline void its_init_mod(struct module *mod) { }
135+
static inline void its_fini_mod(struct module *mod) { }
136+
static inline void its_free_mod(struct module *mod) { }
137+
static inline u8 *its_static_thunk(int reg)
138+
{
139+
WARN_ONCE(1, "ITS not compiled in");
140+
141+
return NULL;
142+
}
143+
#endif
144+
145+
#if defined(CONFIG_MITIGATION_RETHUNK) && defined(CONFIG_OBJTOOL)
146+
extern bool cpu_wants_rethunk(void);
147+
extern bool cpu_wants_rethunk_at(void *addr);
148+
#else
149+
static __always_inline bool cpu_wants_rethunk(void)
150+
{
151+
return false;
152+
}
153+
static __always_inline bool cpu_wants_rethunk_at(void *addr)
154+
{
155+
return false;
156+
}
157+
#endif
158+
127159
#ifdef CONFIG_SMP
128160
extern void alternatives_smp_module_add(struct module *mod, char *name,
129161
void *locks, void *locks_end,

arch/x86/include/asm/cpufeatures.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@
481481
#define X86_FEATURE_AMD_HETEROGENEOUS_CORES (21*32 + 6) /* Heterogeneous Core Topology */
482482
#define X86_FEATURE_AMD_WORKLOAD_CLASS (21*32 + 7) /* Workload Classification */
483483
#define X86_FEATURE_PREFER_YMM (21*32 + 8) /* Avoid ZMM registers due to downclocking */
484+
#define X86_FEATURE_INDIRECT_THUNK_ITS (21*32 + 9) /* Use thunk for indirect branches in lower half of cacheline */
484485

485486
/*
486487
* BUG word(s)
@@ -533,4 +534,6 @@
533534
#define X86_BUG_BHI X86_BUG(1*32 + 3) /* "bhi" CPU is affected by Branch History Injection */
534535
#define X86_BUG_IBPB_NO_RET X86_BUG(1*32 + 4) /* "ibpb_no_ret" IBPB omits return target predictions */
535536
#define X86_BUG_SPECTRE_V2_USER X86_BUG(1*32 + 5) /* "spectre_v2_user" CPU is affected by Spectre variant 2 attack between user processes */
537+
#define X86_BUG_ITS X86_BUG(1*32 + 6) /* "its" CPU is affected by Indirect Target Selection */
538+
#define X86_BUG_ITS_NATIVE_ONLY X86_BUG(1*32 + 7) /* "its_native_only" CPU is affected by ITS, VMX is not affected */
536539
#endif /* _ASM_X86_CPUFEATURES_H */

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@
211211
* VERW clears CPU Register
212212
* File.
213213
*/
214+
#define ARCH_CAP_ITS_NO BIT_ULL(62) /*
215+
* Not susceptible to
216+
* Indirect Target Selection.
217+
* This bit is not set by
218+
* HW, but is synthesized by
219+
* VMMs for guests to know
220+
* their affected status.
221+
*/
214222

215223
#define MSR_IA32_FLUSH_CMD 0x0000010b
216224
#define L1D_FLUSH BIT(0) /*

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,14 @@
336336

337337
#else /* __ASSEMBLER__ */
338338

339+
#define ITS_THUNK_SIZE 64
340+
339341
typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE];
342+
typedef u8 its_thunk_t[ITS_THUNK_SIZE];
340343
extern retpoline_thunk_t __x86_indirect_thunk_array[];
341344
extern retpoline_thunk_t __x86_indirect_call_thunk_array[];
342345
extern retpoline_thunk_t __x86_indirect_jump_thunk_array[];
346+
extern its_thunk_t __x86_indirect_its_thunk_array[];
343347

344348
#ifdef CONFIG_MITIGATION_RETHUNK
345349
extern void __x86_return_thunk(void);
@@ -363,6 +367,12 @@ static inline void srso_return_thunk(void) {}
363367
static inline void srso_alias_return_thunk(void) {}
364368
#endif
365369

370+
#ifdef CONFIG_MITIGATION_ITS
371+
extern void its_return_thunk(void);
372+
#else
373+
static inline void its_return_thunk(void) {}
374+
#endif
375+
366376
extern void retbleed_return_thunk(void);
367377
extern void srso_return_thunk(void);
368378
extern void srso_alias_return_thunk(void);

0 commit comments

Comments
 (0)