public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/23] SRSO fixes/cleanups
@ 2023-08-25  7:01 Josh Poimboeuf
  2023-08-25  7:01 ` [PATCH 01/23] x86/srso: Fix srso_show_state() side effect Josh Poimboeuf
                   ` (24 more replies)
  0 siblings, 25 replies; 71+ messages in thread
From: Josh Poimboeuf @ 2023-08-25  7:01 UTC (permalink / raw)
  To: x86
  Cc: linux-kernel, Borislav Petkov, Peter Zijlstra, Babu Moger,
	Paolo Bonzini, Sean Christopherson, David.Kaplan, Andrew Cooper,
	Nikolay Borisov, gregkh, Thomas Gleixner

v2:
- reorder everything: fixes/functionality before cleanups
- split up KVM patch, add Sean's changes
- add patch to support live migration
- remove "default:" case for enums throughout bugs.c
- various minor tweaks based on v1 discussions with Boris
- add Reviewed-by's

Josh Poimboeuf (23):
  x86/srso: Fix srso_show_state() side effect
  x86/srso: Set CPUID feature bits independently of bug or mitigation
    status
  x86/srso: Don't probe microcode in a guest
  KVM: x86: Add IBPB_BRTYPE support
  KVM: x86: Add SBPB support
  x86/srso: Fix SBPB enablement for spec_rstack_overflow=off
  x86/srso: Fix SBPB enablement for (possible) future fixed HW
  x86/srso: Print actual mitigation if requested mitigation isn't
    possible
  x86/srso: Print mitigation for retbleed IBPB case
  x86/srso: Fix vulnerability reporting for missing microcode
  x86/srso: Fix unret validation dependencies
  x86/alternatives: Remove faulty optimization
  x86/srso: Improve i-cache locality for alias mitigation
  x86/srso: Unexport untraining functions
  x86/srso: Remove 'pred_cmd' label
  x86/bugs: Remove default case for fully switched enums
  x86/srso: Move retbleed IBPB check into existing 'has_microcode' code
    block
  x86/srso: Remove redundant X86_FEATURE_ENTRY_IBPB check
  x86/srso: Disentangle rethunk-dependent options
  x86/rethunk: Use SYM_CODE_START[_LOCAL]_NOALIGN macros
  x86/retpoline: Remove .text..__x86.return_thunk section
  x86/nospec: Refactor UNTRAIN_RET[_*]
  x86/calldepth: Rename __x86_return_skl() to call_depth_return_thunk()

 Documentation/admin-guide/hw-vuln/srso.rst |  22 ++-
 arch/x86/include/asm/nospec-branch.h       |  69 ++++-----
 arch/x86/include/asm/processor.h           |   2 -
 arch/x86/kernel/alternative.c              |   8 -
 arch/x86/kernel/cpu/amd.c                  |  28 ++--
 arch/x86/kernel/cpu/bugs.c                 | 104 ++++++-------
 arch/x86/kernel/vmlinux.lds.S              |  10 +-
 arch/x86/kvm/cpuid.c                       |   5 +-
 arch/x86/kvm/cpuid.h                       |   3 +-
 arch/x86/kvm/x86.c                         |  29 +++-
 arch/x86/lib/retpoline.S                   | 171 +++++++++++----------
 include/linux/objtool.h                    |   3 +-
 scripts/Makefile.vmlinux_o                 |   3 +-
 13 files changed, 230 insertions(+), 227 deletions(-)

-- 
2.41.0


^ permalink raw reply	[flat|nested] 71+ messages in thread
* [PATCH v3 08/20] x86/srso: Fix vulnerability reporting for missing microcode
@ 2023-09-05  5:04 Josh Poimboeuf
  2023-09-05 10:09 ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
                   ` (3 more replies)
  0 siblings, 4 replies; 71+ messages in thread
From: Josh Poimboeuf @ 2023-09-05  5:04 UTC (permalink / raw)
  To: x86
  Cc: linux-kernel, Borislav Petkov, Peter Zijlstra, Babu Moger,
	Paolo Bonzini, Sean Christopherson, David.Kaplan, Andrew Cooper,
	Nikolay Borisov, gregkh, Thomas Gleixner

The SRSO default safe-ret mitigation is reported as "mitigated" even if
microcode hasn't been updated.  That's wrong because userspace may still
be vulnerable to SRSO attacks due to IBPB not flushing branch type
predictions.

Report the safe-ret + !microcode case as vulnerable.

Also report the microcode-only case as vulnerable as it leaves the
kernel open to attacks.

Fixes: fb3bd914b3ec ("x86/srso: Add a Speculative RAS Overflow mitigation")
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 Documentation/admin-guide/hw-vuln/srso.rst | 24 ++++++++++-----
 arch/x86/kernel/cpu/bugs.c                 | 36 +++++++++++++---------
 2 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/Documentation/admin-guide/hw-vuln/srso.rst b/Documentation/admin-guide/hw-vuln/srso.rst
index b6cfb51cb0b4..e715bfc09879 100644
--- a/Documentation/admin-guide/hw-vuln/srso.rst
+++ b/Documentation/admin-guide/hw-vuln/srso.rst
@@ -46,12 +46,22 @@ The possible values in this file are:
 
    The processor is not vulnerable
 
- * 'Vulnerable: no microcode':
+* 'Vulnerable':
+
+   The processor is vulnerable and no mitigations have been applied.
+
+ * 'Vulnerable: No microcode':
 
    The processor is vulnerable, no microcode extending IBPB
    functionality to address the vulnerability has been applied.
 
- * 'Mitigation: microcode':
+ * 'Vulnerable: Safe RET, no microcode':
+
+   The "Safe RET" mitigation (see below) has been applied to protect the
+   kernel, but the IBPB-extending microcode has not been applied.  User
+   space tasks may still be vulnerable.
+
+ * 'Vulnerable: Microcode, no safe RET':
 
    Extended IBPB functionality microcode patch has been applied. It does
    not address User->Kernel and Guest->Host transitions protection but it
@@ -72,11 +82,11 @@ The possible values in this file are:
 
    (spec_rstack_overflow=microcode)
 
- * 'Mitigation: safe RET':
+ * 'Mitigation: Safe RET':
 
-   Software-only mitigation. It complements the extended IBPB microcode
-   patch functionality by addressing User->Kernel and Guest->Host
-   transitions protection.
+   Combined microcode/software mitigation. It complements the
+   extended IBPB microcode patch functionality by addressing
+   User->Kernel and Guest->Host transitions protection.
 
    Selected by default or by spec_rstack_overflow=safe-ret
 
@@ -129,7 +139,7 @@ an indrect branch prediction barrier after having applied the required
 microcode patch for one's system. This mitigation comes also at
 a performance cost.
 
-Mitigation: safe RET
+Mitigation: Safe RET
 --------------------
 
 The mitigation works by ensuring all RET instructions speculate to
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 6c47f37515b8..e45dd69aff7f 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -2353,6 +2353,8 @@ early_param("l1tf", l1tf_cmdline);
 
 enum srso_mitigation {
 	SRSO_MITIGATION_NONE,
+	SRSO_MITIGATION_UCODE_NEEDED,
+	SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED,
 	SRSO_MITIGATION_MICROCODE,
 	SRSO_MITIGATION_SAFE_RET,
 	SRSO_MITIGATION_IBPB,
@@ -2368,11 +2370,13 @@ enum srso_mitigation_cmd {
 };
 
 static const char * const srso_strings[] = {
-	[SRSO_MITIGATION_NONE]           = "Vulnerable",
-	[SRSO_MITIGATION_MICROCODE]      = "Mitigation: microcode",
-	[SRSO_MITIGATION_SAFE_RET]	 = "Mitigation: safe RET",
-	[SRSO_MITIGATION_IBPB]		 = "Mitigation: IBPB",
-	[SRSO_MITIGATION_IBPB_ON_VMEXIT] = "Mitigation: IBPB on VMEXIT only"
+	[SRSO_MITIGATION_NONE]			= "Vulnerable",
+	[SRSO_MITIGATION_UCODE_NEEDED]		= "Vulnerable: No microcode",
+	[SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED]	= "Vulnerable: Safe RET, no microcode",
+	[SRSO_MITIGATION_MICROCODE]		= "Vulnerable: Microcode, no safe RET",
+	[SRSO_MITIGATION_SAFE_RET]		= "Mitigation: Safe RET",
+	[SRSO_MITIGATION_IBPB]			= "Mitigation: IBPB",
+	[SRSO_MITIGATION_IBPB_ON_VMEXIT]	= "Mitigation: IBPB on VMEXIT only"
 };
 
 static enum srso_mitigation srso_mitigation __ro_after_init = SRSO_MITIGATION_NONE;
@@ -2409,10 +2413,7 @@ static void __init srso_select_mitigation(void)
 	if (!boot_cpu_has_bug(X86_BUG_SRSO) || cpu_mitigations_off())
 		goto pred_cmd;
 
-	if (!has_microcode) {
-		pr_warn("IBPB-extending microcode not applied!\n");
-		pr_warn(SRSO_NOTICE);
-	} else {
+	if (has_microcode) {
 		/*
 		 * Zen1/2 with SMT off aren't vulnerable after the right
 		 * IBPB microcode has been applied.
@@ -2428,6 +2429,12 @@ static void __init srso_select_mitigation(void)
 			srso_mitigation = SRSO_MITIGATION_IBPB;
 			goto out;
 		}
+	} else {
+		pr_warn("IBPB-extending microcode not applied!\n");
+		pr_warn(SRSO_NOTICE);
+
+		/* may be overwritten by SRSO_CMD_SAFE_RET below */
+		srso_mitigation = SRSO_MITIGATION_UCODE_NEEDED;
 	}
 
 	switch (srso_cmd) {
@@ -2457,7 +2464,10 @@ static void __init srso_select_mitigation(void)
 				setup_force_cpu_cap(X86_FEATURE_SRSO);
 				x86_return_thunk = srso_return_thunk;
 			}
-			srso_mitigation = SRSO_MITIGATION_SAFE_RET;
+			if (has_microcode)
+				srso_mitigation = SRSO_MITIGATION_SAFE_RET;
+			else
+				srso_mitigation = SRSO_MITIGATION_SAFE_RET_UCODE_NEEDED;
 		} else {
 			pr_err("WARNING: kernel not compiled with CPU_SRSO.\n");
 		}
@@ -2490,7 +2500,7 @@ static void __init srso_select_mitigation(void)
 	}
 
 out:
-	pr_info("%s%s\n", srso_strings[srso_mitigation], has_microcode ? "" : ", no microcode");
+	pr_info("%s\n", srso_strings[srso_mitigation]);
 
 pred_cmd:
 	if ((!boot_cpu_has_bug(X86_BUG_SRSO) || srso_cmd == SRSO_CMD_OFF) &&
@@ -2701,9 +2711,7 @@ static ssize_t srso_show_state(char *buf)
 	if (boot_cpu_has(X86_FEATURE_SRSO_NO))
 		return sysfs_emit(buf, "Mitigation: SMT disabled\n");
 
-	return sysfs_emit(buf, "%s%s\n",
-			  srso_strings[srso_mitigation],
-			  boot_cpu_has(X86_FEATURE_IBPB_BRTYPE) ? "" : ", no microcode");
+	return sysfs_emit(buf, "%s\n", srso_strings[srso_mitigation]);
 }
 
 static ssize_t gds_show_state(char *buf)
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 71+ messages in thread

end of thread, other threads:[~2023-10-20 11:38 UTC | newest]

Thread overview: 71+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-25  7:01 [PATCH v2 00/23] SRSO fixes/cleanups Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 01/23] x86/srso: Fix srso_show_state() side effect Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 02/23] x86/srso: Set CPUID feature bits independently of bug or mitigation status Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 03/23] x86/srso: Don't probe microcode in a guest Josh Poimboeuf
2023-08-25  7:52   ` Andrew Cooper
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 04/23] KVM: x86: Add IBPB_BRTYPE support Josh Poimboeuf
2023-08-25 18:15   ` Sean Christopherson
2023-08-26 15:49     ` Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 05/23] KVM: x86: Add SBPB support Josh Poimboeuf
2023-08-25 18:20   ` Sean Christopherson
2023-08-25  7:01 ` [PATCH 06/23] x86/srso: Fix SBPB enablement for spec_rstack_overflow=off Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 07/23] x86/srso: Fix SBPB enablement for (possible) future fixed HW Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 08/23] x86/srso: Print actual mitigation if requested mitigation isn't possible Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 09/23] x86/srso: Print mitigation for retbleed IBPB case Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 10/23] x86/srso: Fix vulnerability reporting for missing microcode Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-09-01  9:40     ` Borislav Petkov
2023-09-02 10:46       ` Ingo Molnar
2023-09-02 17:04         ` Borislav Petkov
2023-09-03 14:37           ` Borislav Petkov
2023-09-05  4:57         ` Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 11/23] x86/srso: Fix unret validation dependencies Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 12/23] x86/alternatives: Remove faulty optimization Josh Poimboeuf
2023-08-25  9:20   ` Ingo Molnar
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25 10:27   ` [tip: x86/urgent] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 13/23] x86/srso: Improve i-cache locality for alias mitigation Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 14/23] x86/srso: Unexport untraining functions Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 15/23] x86/srso: Remove 'pred_cmd' label Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25 19:51   ` [PATCH 15/23] " Nikolay Borisov
2023-08-26 15:45     ` Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 16/23] x86/bugs: Remove default case for fully switched enums Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-09-02  9:02   ` [PATCH 16/23] " Borislav Petkov
2023-09-05  5:08     ` Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 17/23] x86/srso: Move retbleed IBPB check into existing 'has_microcode' code block Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 18/23] x86/srso: Remove redundant X86_FEATURE_ENTRY_IBPB check Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-09-02  9:10   ` [PATCH 18/23] " Borislav Petkov
2023-08-25  7:01 ` [PATCH 19/23] x86/srso: Disentangle rethunk-dependent options Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 20/23] x86/rethunk: Use SYM_CODE_START[_LOCAL]_NOALIGN macros Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 21/23] x86/retpoline: Remove .text..__x86.return_thunk section Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 22/23] x86/nospec: Refactor UNTRAIN_RET[_*] Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25 18:22   ` [PATCH 22/23] " Nikolay Borisov
2023-08-26 15:42     ` Josh Poimboeuf
2023-08-25  7:01 ` [PATCH 23/23] x86/calldepth: Rename __x86_return_skl() to call_depth_return_thunk() Josh Poimboeuf
2023-08-25 10:19   ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-08-25 10:38 ` [PATCH v2 00/23] SRSO fixes/cleanups Ingo Molnar
2023-08-26 15:57   ` Josh Poimboeuf
2023-08-26 17:00     ` Ingo Molnar
2023-10-05  1:29 ` Sean Christopherson
  -- strict thread matches above, loose matches on Subject: below --
2023-09-05  5:04 [PATCH v3 08/20] x86/srso: Fix vulnerability reporting for missing microcode Josh Poimboeuf
2023-09-05 10:09 ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-09-19  9:53 ` tip-bot2 for Josh Poimboeuf
2023-09-23 12:20 ` tip-bot2 for Josh Poimboeuf
2023-10-20 11:37 ` tip-bot2 for Josh Poimboeuf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox