Skip to content

Commit 6921ed9

Browse files
sinkapbp3tk0v
authored andcommitted
x86/speculation: Allow enabling STIBP with legacy IBRS
When plain IBRS is enabled (not enhanced IBRS), the logic in spectre_v2_user_select_mitigation() determines that STIBP is not needed. The IBRS bit implicitly protects against cross-thread branch target injection. However, with legacy IBRS, the IBRS bit is cleared on returning to userspace for performance reasons which leaves userspace threads vulnerable to cross-thread branch target injection against which STIBP protects. Exclude IBRS from the spectre_v2_in_ibrs_mode() check to allow for enabling STIBP (through seccomp/prctl() by default or always-on, if selected by spectre_v2_user kernel cmdline parameter). [ bp: Massage. ] Fixes: 7c693f5 ("x86/speculation: Add spectre_v2=ibrs option to support Kernel IBRS") Reported-by: José Oliveira <[email protected]> Reported-by: Rodrigo Branco <[email protected]> Signed-off-by: KP Singh <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 8779347 commit 6921ed9

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,14 +1133,18 @@ spectre_v2_parse_user_cmdline(void)
11331133
return SPECTRE_V2_USER_CMD_AUTO;
11341134
}
11351135

1136-
static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode)
1136+
static inline bool spectre_v2_in_eibrs_mode(enum spectre_v2_mitigation mode)
11371137
{
1138-
return mode == SPECTRE_V2_IBRS ||
1139-
mode == SPECTRE_V2_EIBRS ||
1138+
return mode == SPECTRE_V2_EIBRS ||
11401139
mode == SPECTRE_V2_EIBRS_RETPOLINE ||
11411140
mode == SPECTRE_V2_EIBRS_LFENCE;
11421141
}
11431142

1143+
static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode)
1144+
{
1145+
return spectre_v2_in_eibrs_mode(mode) || mode == SPECTRE_V2_IBRS;
1146+
}
1147+
11441148
static void __init
11451149
spectre_v2_user_select_mitigation(void)
11461150
{
@@ -1203,12 +1207,19 @@ spectre_v2_user_select_mitigation(void)
12031207
}
12041208

12051209
/*
1206-
* If no STIBP, IBRS or enhanced IBRS is enabled, or SMT impossible,
1207-
* STIBP is not required.
1210+
* If no STIBP, enhanced IBRS is enabled, or SMT impossible, STIBP
1211+
* is not required.
1212+
*
1213+
* Enhanced IBRS also protects against cross-thread branch target
1214+
* injection in user-mode as the IBRS bit remains always set which
1215+
* implicitly enables cross-thread protections. However, in legacy IBRS
1216+
* mode, the IBRS bit is set only on kernel entry and cleared on return
1217+
* to userspace. This disables the implicit cross-thread protection,
1218+
* so allow for STIBP to be selected in that case.
12081219
*/
12091220
if (!boot_cpu_has(X86_FEATURE_STIBP) ||
12101221
!smt_possible ||
1211-
spectre_v2_in_ibrs_mode(spectre_v2_enabled))
1222+
spectre_v2_in_eibrs_mode(spectre_v2_enabled))
12121223
return;
12131224

12141225
/*
@@ -2340,7 +2351,7 @@ static ssize_t mmio_stale_data_show_state(char *buf)
23402351

23412352
static char *stibp_state(void)
23422353
{
2343-
if (spectre_v2_in_ibrs_mode(spectre_v2_enabled))
2354+
if (spectre_v2_in_eibrs_mode(spectre_v2_enabled))
23442355
return "";
23452356

23462357
switch (spectre_v2_user_stibp) {

0 commit comments

Comments
 (0)