patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: David Kaplan <david.kaplan@amd.com>,
	"Borislav Petkov (AMD)" <bp@alien8.de>,
	Sasha Levin <sashal@kernel.org>,
	tglx@linutronix.de, peterz@infradead.org, jpoimboe@kernel.org
Subject: [PATCH AUTOSEL 6.17-5.4] x86/bugs: Fix reporting of LFENCE retpoline
Date: Mon,  6 Oct 2025 14:17:56 -0400	[thread overview]
Message-ID: <20251006181835.1919496-24-sashal@kernel.org> (raw)
In-Reply-To: <20251006181835.1919496-1-sashal@kernel.org>

From: David Kaplan <david.kaplan@amd.com>

[ Upstream commit d1cc1baef67ac6c09b74629ca053bf3fb812f7dc ]

The LFENCE retpoline mitigation is not secure but the kernel prints
inconsistent messages about this fact.  The dmesg log says 'Mitigation:
LFENCE', implying the system is mitigated.  But sysfs reports 'Vulnerable:
LFENCE' implying the system (correctly) is not mitigated.

Fix this by printing a consistent 'Vulnerable: LFENCE' string everywhere
when this mitigation is selected.

Signed-off-by: David Kaplan <david.kaplan@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/20250915134706.3201818-1-david.kaplan@amd.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

Based on my comprehensive analysis of this commit and its historical
context, here is my determination:

## **Backport Status: YES**

## Extensive Analysis

### Historical Context and Bug Origins

The LFENCE reporting inconsistency was introduced in **February 2022**
by commit **eafd987d4a82c** ("x86/speculation: Warn about Spectre v2
LFENCE mitigation"). That commit revealed that:

1. **Neither Intel nor AMD recommend LFENCE retpoline anymore** - it's
   faster than regular retpoline but weaker in certain scenarios
   (particularly SMT)
2. Intel's STORM research team discovered that AMD's LFENCE/JMP
   mitigation is insufficient due to a race condition
3. AMD confirmed the findings and recommended using alternative
   mitigations (generic retpoline or IBRS)

The 2022 commit added `return sprintf(buf, "Vulnerable: LFENCE\n");` to
the sysfs reporting function but **forgot to update the
`spectre_v2_strings[]` array**, which still said `"Mitigation: LFENCE"`.
This created a **3-year inconsistency** (2022-2025).

### What This Commit Fixes

Looking at the code changes in arch/x86/kernel/cpu/bugs.c:

**Line 2037** (spectre_v2_strings array):
```c
-[SPECTRE_V2_LFENCE] = "Mitigation: LFENCE",
+[SPECTRE_V2_LFENCE] = "Vulnerable: LFENCE",
```

**Lines 3544-3546** (spectre_v2_show_state function):
```c
-if (spectre_v2_enabled == SPECTRE_V2_LFENCE)
- return sysfs_emit(buf, "Vulnerable: LFENCE\n");
-
```

The special case is removed because now
`spectre_v2_strings[spectre_v2_enabled]` already returns the correct
"Vulnerable: LFENCE" string at line 3571.

### Verification That This Is Purely a Reporting Fix

By examining the code at lines 1631, 2160, and 2418, I confirmed that
`SPECTRE_V2_LFENCE` is used throughout the code for actual mitigation
logic (setting CPU features, configuring RSB filling, etc.). **This
commit changes ONLY the display strings** - it doesn't touch any
mitigation behavior.

### Impact and User Confusion

**Before this fix:**
- **dmesg log**: "Mitigation: LFENCE" (misleading - implies system is
  protected)
- **sysfs** (`/sys/devices/system/cpu/vulnerabilities/spectre_v2`):
  "Vulnerable: LFENCE" (correct)

**After this fix:**
- **Both locations**: "Vulnerable: LFENCE" (consistent and correct)

This inconsistency could:
1. Mislead system administrators about their security posture
2. Confuse security scanning tools (like spectre-meltdown-checker) that
   parse these strings
3. Cause incorrect security audits and compliance checks
4. Make users think they're protected when they're not

### Why This Should Be Backported

1. **Fixes Important Security Information Bug**: Users need accurate
   information about their vulnerability status to make informed
   security decisions

2. **Very Small and Low-Risk Change**:
   - Only 7 lines changed (1 string modified, 3 lines removed)
   - No behavioral changes to actual mitigations
   - Self-contained in a single file
   - No side effects

3. **Long-standing Bug**: The inconsistency has existed since the 2022
   security advisory (commit eafd987d4a82c)

4. **Affects Stable Kernels**: Any stable kernel that includes the 2022
   warning commit should also get this fix to ensure consistent
   reporting

5. **Minimal Risk of Regression**: Since it only changes display
   strings, there's virtually no risk of introducing new bugs or
   breaking existing functionality

6. **Follows Stable Kernel Rules**:
   - Important bugfix ✓
   - Minimal risk ✓
   - Small and self-contained ✓
   - Fixes user-visible issue ✓

### Missing Tags

The commit lacks a `Fixes:` tag (should reference eafd987d4a82c) and has
no `Cc: stable@vger.kernel.org` tag, but these are likely oversights
given the clear nature of the fix.

### Conclusion

**YES, this commit should be backported** to all stable kernel trees
that contain commit eafd987d4a82c (v5.16+). It fixes misleading security
information that could confuse users and tools, with virtually zero risk
of regression since it only affects display strings.

 arch/x86/kernel/cpu/bugs.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index b633b026c117d..692293f0bc1bb 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -2050,7 +2050,7 @@ static void __init spectre_v2_user_apply_mitigation(void)
 static const char * const spectre_v2_strings[] = {
 	[SPECTRE_V2_NONE]			= "Vulnerable",
 	[SPECTRE_V2_RETPOLINE]			= "Mitigation: Retpolines",
-	[SPECTRE_V2_LFENCE]			= "Mitigation: LFENCE",
+	[SPECTRE_V2_LFENCE]			= "Vulnerable: LFENCE",
 	[SPECTRE_V2_EIBRS]			= "Mitigation: Enhanced / Automatic IBRS",
 	[SPECTRE_V2_EIBRS_LFENCE]		= "Mitigation: Enhanced / Automatic IBRS + LFENCE",
 	[SPECTRE_V2_EIBRS_RETPOLINE]		= "Mitigation: Enhanced / Automatic IBRS + Retpolines",
@@ -3634,9 +3634,6 @@ static const char *spectre_bhi_state(void)
 
 static ssize_t spectre_v2_show_state(char *buf)
 {
-	if (spectre_v2_enabled == SPECTRE_V2_LFENCE)
-		return sysfs_emit(buf, "Vulnerable: LFENCE\n");
-
 	if (spectre_v2_enabled == SPECTRE_V2_EIBRS && unprivileged_ebpf_enabled())
 		return sysfs_emit(buf, "Vulnerable: eIBRS with unprivileged eBPF\n");
 
-- 
2.51.0


  parent reply	other threads:[~2025-10-06 18:19 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-06 18:17 [PATCH AUTOSEL 6.17-5.4] x86/build: Remove cc-option from stack alignment flags Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.1] btrfs: zoned: refine extent allocator hint selection Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.1] arch: Add the macro COMPILE_OFFSETS to all the asm-offsets.c Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.12] btrfs: abort transaction on specific error places when walking log tree Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-5.4] btrfs: use smp_mb__after_atomic() when forcing COW in create_pending_snapshot() Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17] x86/bugs: Add attack vector controls for VMSCAPE Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.16] sched_ext: Keep bypass on between enable failure and scx_disable_workfn() Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.12] perf/x86/intel: Add ICL_FIXED_0_ADAPTIVE bit into INTEL_FIXED_BITS_MASK Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.12] btrfs: abort transaction if we fail to update inode in log replay dir fixup Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.1] EDAC/mc_sysfs: Increase legacy channel support to 16 Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.12] btrfs: abort transaction in the process_one_buffer() log tree walk callback Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.6] btrfs: zoned: return error from btrfs_zone_finish_endio() Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.6] perf: Skip user unwind if the task is a kernel thread Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.1] perf: Have get_perf_callchain() return NULL if crosstask and user are set Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.16] EDAC: Fix wrong executable file modes for C source files Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.6] perf: Use current->flags & PF_KTHREAD|PF_USER_WORKER instead of current->mm == NULL Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.6] btrfs: use level argument in log tree walk callback replay_one_buffer() Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.12] sched_ext: Make qmap dump operation non-destructive Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.12] seccomp: passthrough uprobe systemcall without filtering Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.12] cpuset: Use new excpus for nocpu error check when enabling root partition Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.12] btrfs: tree-checker: add inode extref checks Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17] sched/fair: update_cfs_group() for throttled cfs_rqs Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-5.15] btrfs: scrub: replace max_t()/min_t() with clamp() in scrub_throttle_dev_io() Sasha Levin
2025-10-06 18:17 ` Sasha Levin [this message]
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-5.10] btrfs: always drop log root tree reference in btrfs_replay_log() Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17-6.6] audit: record fanotify event regardless of presence of rules Sasha Levin
2025-10-06 18:17 ` [PATCH AUTOSEL 6.17] EDAC/ie31200: Add two more Intel Alder Lake-S SoCs for EDAC support Sasha Levin
2025-10-06 18:18 ` [PATCH AUTOSEL 6.17-6.6] x86/bugs: Report correct retbleed mitigation status Sasha Levin
2025-10-06 21:55 ` [PATCH AUTOSEL 6.17-5.4] x86/build: Remove cc-option from stack alignment flags Nathan Chancellor
2025-10-06 23:13   ` Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251006181835.1919496-24-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=bp@alien8.de \
    --cc=david.kaplan@amd.com \
    --cc=jpoimboe@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).