Commit fd470a8b authored by Kim Phillips's avatar Kim Phillips Committed by Borislav Petkov (AMD)

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: e7862eda ("x86/cpu: Support AMD Automatic IBRS")
Reported-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: default avatarKim Phillips <kim.phillips@amd.com>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20230720194727.67022-1-kim.phillips@amd.com
parent 3ba2e833
...@@ -484,11 +484,14 @@ Spectre variant 2 ...@@ -484,11 +484,14 @@ Spectre variant 2
Systems which support enhanced IBRS (eIBRS) enable IBRS protection once at Systems which support enhanced IBRS (eIBRS) enable IBRS protection once at
boot, by setting the IBRS bit, and they're automatically protected against boot, by setting the IBRS bit, and they're automatically protected against
Spectre v2 variant attacks, including cross-thread branch target injections Spectre v2 variant attacks.
on SMT systems (STIBP). In other words, eIBRS enables STIBP too.
Legacy IBRS systems clear the IBRS bit on exit to userspace and On Intel's enhanced IBRS systems, this includes cross-thread branch target
therefore explicitly enable STIBP for that injections on SMT systems (STIBP). In other words, Intel eIBRS enables
STIBP, too.
AMD Automatic IBRS does not protect userspace, and Legacy IBRS systems clear
the IBRS bit on exit to userspace, therefore both explicitly enable STIBP.
The retpoline mitigation is turned on by default on vulnerable The retpoline mitigation is turned on by default on vulnerable
CPUs. It can be forced on or off by the administrator CPUs. It can be forced on or off by the administrator
......
...@@ -1150,19 +1150,21 @@ spectre_v2_user_select_mitigation(void) ...@@ -1150,19 +1150,21 @@ spectre_v2_user_select_mitigation(void)
} }
/* /*
* If no STIBP, enhanced IBRS is enabled, or SMT impossible, STIBP * If no STIBP, Intel enhanced IBRS is enabled, or SMT impossible, STIBP
* is not required. * is not required.
* *
* Enhanced IBRS also protects against cross-thread branch target * Intel's Enhanced IBRS also protects against cross-thread branch target
* injection in user-mode as the IBRS bit remains always set which * injection in user-mode as the IBRS bit remains always set which
* implicitly enables cross-thread protections. However, in legacy IBRS * implicitly enables cross-thread protections. However, in legacy IBRS
* mode, the IBRS bit is set only on kernel entry and cleared on return * mode, the IBRS bit is set only on kernel entry and cleared on return
* to userspace. This disables the implicit cross-thread protection, * to userspace. AMD Automatic IBRS also does not protect userspace.
* so allow for STIBP to be selected in that case. * These modes therefore disable the implicit cross-thread protection,
* so allow for STIBP to be selected in those cases.
*/ */
if (!boot_cpu_has(X86_FEATURE_STIBP) || if (!boot_cpu_has(X86_FEATURE_STIBP) ||
!smt_possible || !smt_possible ||
spectre_v2_in_eibrs_mode(spectre_v2_enabled)) (spectre_v2_in_eibrs_mode(spectre_v2_enabled) &&
!boot_cpu_has(X86_FEATURE_AUTOIBRS)))
return; return;
/* /*
...@@ -2294,7 +2296,8 @@ static ssize_t mmio_stale_data_show_state(char *buf) ...@@ -2294,7 +2296,8 @@ static ssize_t mmio_stale_data_show_state(char *buf)
static char *stibp_state(void) static char *stibp_state(void)
{ {
if (spectre_v2_in_eibrs_mode(spectre_v2_enabled)) if (spectre_v2_in_eibrs_mode(spectre_v2_enabled) &&
!boot_cpu_has(X86_FEATURE_AUTOIBRS))
return ""; return "";
switch (spectre_v2_user_stibp) { switch (spectre_v2_user_stibp) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment