Skip to content

Commit 37136bb

Browse files
committed
x86/speculation: Allow enabling STIBP with legacy IBRS
jira LE-1907 cve CVE-2023-1998 Rebuild_History Non-Buildable kernel-5.14.0-284.30.1.el9_2 commit-author KP Singh <kpsingh@kernel.org> commit 6921ed9 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 <joseloliveira11@gmail.com> Reported-by: Rodrigo Branco <rodrigo@kernelhacking.com> Signed-off-by: KP Singh <kpsingh@kernel.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20230220120127.1975241-1-kpsingh@kernel.org Link: https://lore.kernel.org/r/20230221184908.2349578-1-kpsingh@kernel.org (cherry picked from commit 6921ed9) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent b03c521 commit 37136bb

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
@@ -1095,14 +1095,18 @@ spectre_v2_parse_user_cmdline(void)
10951095
return SPECTRE_V2_USER_CMD_AUTO;
10961096
}
10971097

1098-
static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode)
1098+
static inline bool spectre_v2_in_eibrs_mode(enum spectre_v2_mitigation mode)
10991099
{
1100-
return mode == SPECTRE_V2_IBRS ||
1101-
mode == SPECTRE_V2_EIBRS ||
1100+
return mode == SPECTRE_V2_EIBRS ||
11021101
mode == SPECTRE_V2_EIBRS_RETPOLINE ||
11031102
mode == SPECTRE_V2_EIBRS_LFENCE;
11041103
}
11051104

1105+
static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode)
1106+
{
1107+
return spectre_v2_in_eibrs_mode(mode) || mode == SPECTRE_V2_IBRS;
1108+
}
1109+
11061110
static void __init
11071111
spectre_v2_user_select_mitigation(void)
11081112
{
@@ -1165,12 +1169,19 @@ spectre_v2_user_select_mitigation(void)
11651169
}
11661170

11671171
/*
1168-
* If no STIBP, IBRS or enhanced IBRS is enabled, or SMT impossible,
1169-
* STIBP is not required.
1172+
* If no STIBP, enhanced IBRS is enabled, or SMT impossible, STIBP
1173+
* is not required.
1174+
*
1175+
* Enhanced IBRS also protects against cross-thread branch target
1176+
* injection in user-mode as the IBRS bit remains always set which
1177+
* implicitly enables cross-thread protections. However, in legacy IBRS
1178+
* mode, the IBRS bit is set only on kernel entry and cleared on return
1179+
* to userspace. This disables the implicit cross-thread protection,
1180+
* so allow for STIBP to be selected in that case.
11701181
*/
11711182
if (!boot_cpu_has(X86_FEATURE_STIBP) ||
11721183
!smt_possible ||
1173-
spectre_v2_in_ibrs_mode(spectre_v2_enabled))
1184+
spectre_v2_in_eibrs_mode(spectre_v2_enabled))
11741185
return;
11751186

11761187
/*
@@ -2295,7 +2306,7 @@ static ssize_t mmio_stale_data_show_state(char *buf)
22952306

22962307
static char *stibp_state(void)
22972308
{
2298-
if (spectre_v2_in_ibrs_mode(spectre_v2_enabled))
2309+
if (spectre_v2_in_eibrs_mode(spectre_v2_enabled))
22992310
return "";
23002311

23012312
switch (spectre_v2_user_stibp) {

0 commit comments

Comments
 (0)