Skip to content

Commit fd470a8

Browse files
kimphillamdbp3tk0v
authored andcommitted
x86/cpu: Enable STIBP on AMD if Automatic IBRS is enabled
Unlike Intel's Enhanced IBRS feature, AMD's Automatic IBRS does not provide protection to processes running at CPL3/user mode, see section "Extended Feature Enable Register (EFER)" in the APM v2 at https://bugzilla.kernel.org/attachment.cgi?id=304652 Explicitly enable STIBP to protect against cross-thread CPL3 branch target injections on systems with Automatic IBRS enabled. Also update the relevant documentation. Fixes: e7862ed ("x86/cpu: Support AMD Automatic IBRS") Reported-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Kim Phillips <kim.phillips@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20230720194727.67022-1-kim.phillips@amd.com
1 parent 3ba2e83 commit fd470a8

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,14 @@ Spectre variant 2
484484

485485
Systems which support enhanced IBRS (eIBRS) enable IBRS protection once at
486486
boot, by setting the IBRS bit, and they're automatically protected against
487-
Spectre v2 variant attacks, including cross-thread branch target injections
488-
on SMT systems (STIBP). In other words, eIBRS enables STIBP too.
487+
Spectre v2 variant attacks.
489488

490-
Legacy IBRS systems clear the IBRS bit on exit to userspace and
491-
therefore explicitly enable STIBP for that
489+
On Intel's enhanced IBRS systems, this includes cross-thread branch target
490+
injections on SMT systems (STIBP). In other words, Intel eIBRS enables
491+
STIBP, too.
492+
493+
AMD Automatic IBRS does not protect userspace, and Legacy IBRS systems clear
494+
the IBRS bit on exit to userspace, therefore both explicitly enable STIBP.
492495

493496
The retpoline mitigation is turned on by default on vulnerable
494497
CPUs. It can be forced on or off by the administrator

arch/x86/kernel/cpu/bugs.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,19 +1150,21 @@ spectre_v2_user_select_mitigation(void)
11501150
}
11511151

11521152
/*
1153-
* If no STIBP, enhanced IBRS is enabled, or SMT impossible, STIBP
1153+
* If no STIBP, Intel enhanced IBRS is enabled, or SMT impossible, STIBP
11541154
* is not required.
11551155
*
1156-
* Enhanced IBRS also protects against cross-thread branch target
1156+
* Intel's Enhanced IBRS also protects against cross-thread branch target
11571157
* injection in user-mode as the IBRS bit remains always set which
11581158
* implicitly enables cross-thread protections. However, in legacy IBRS
11591159
* mode, the IBRS bit is set only on kernel entry and cleared on return
1160-
* to userspace. This disables the implicit cross-thread protection,
1161-
* so allow for STIBP to be selected in that case.
1160+
* to userspace. AMD Automatic IBRS also does not protect userspace.
1161+
* These modes therefore disable the implicit cross-thread protection,
1162+
* so allow for STIBP to be selected in those cases.
11621163
*/
11631164
if (!boot_cpu_has(X86_FEATURE_STIBP) ||
11641165
!smt_possible ||
1165-
spectre_v2_in_eibrs_mode(spectre_v2_enabled))
1166+
(spectre_v2_in_eibrs_mode(spectre_v2_enabled) &&
1167+
!boot_cpu_has(X86_FEATURE_AUTOIBRS)))
11661168
return;
11671169

11681170
/*
@@ -2294,7 +2296,8 @@ static ssize_t mmio_stale_data_show_state(char *buf)
22942296

22952297
static char *stibp_state(void)
22962298
{
2297-
if (spectre_v2_in_eibrs_mode(spectre_v2_enabled))
2299+
if (spectre_v2_in_eibrs_mode(spectre_v2_enabled) &&
2300+
!boot_cpu_has(X86_FEATURE_AUTOIBRS))
22982301
return "";
22992302

23002303
switch (spectre_v2_user_stibp) {

0 commit comments

Comments
 (0)