public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Tomas Henzl <thenzl@redhat.com>,
	David Jeffery <djeffery@redhat.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Sasha Levin <sashal@kernel.org>,
	James.Bottomley@HansenPartnership.com,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH AUTOSEL 6.19-5.10] scsi: ses: Fix devices attaching to different hosts
Date: Thu,  5 Mar 2026 10:36:49 -0500	[thread overview]
Message-ID: <20260305153704.106918-6-sashal@kernel.org> (raw)
In-Reply-To: <20260305153704.106918-1-sashal@kernel.org>

From: Tomas Henzl <thenzl@redhat.com>

[ Upstream commit 70ca8caa96ce473647054f5c7b9dab5423902402 ]

On a multipath SAS system some devices don't end up with correct symlinks
from the SCSI device to its enclosure. Some devices even have enclosure
links pointing to enclosures attached to different SCSI hosts.

ses_match_to_enclosure() calls enclosure_for_each_device() which iterates
over all enclosures on the system, not just enclosures attached to the
current SCSI host.

Replace the iteration with a direct call to ses_enclosure_find_by_addr().

Reviewed-by: David Jeffery <djeffery@redhat.com>
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
Link: https://patch.msgid.link/20260210191850.36784-1-thenzl@redhat.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

## Analysis

### Problem Description
On multipath SAS systems, `ses_match_to_enclosure()` calls
`enclosure_for_each_device(ses_enclosure_find_by_addr, &efd)` at line
687, which iterates over **all** enclosures registered system-wide via
`container_list`. This means a SCSI device can be incorrectly matched to
an enclosure on a completely different SCSI host, resulting in wrong
sysfs symlinks from devices to enclosures.

### The Fix
The fix replaces the global iteration with a direct call:
`ses_enclosure_find_by_addr(edev, &efd)`, which searches only the
specific `edev` enclosure device already passed into
`ses_match_to_enclosure()`. The function signature also changes from
`void *data` to `struct efd *efd` for type safety (since it's no longer
used as a callback for `enclosure_for_each_device`).

### Stable Kernel Criteria Assessment

1. **Obviously correct and tested**: Yes. The `edev` is already the
   correct enclosure for the current host — using the global iterator
   was simply wrong. Reviewed-by David Jeffery (Red Hat), Signed-off-by
   Martin K. Petersen (SCSI maintainer).

2. **Fixes a real bug**: Yes. Incorrect device-to-enclosure associations
   cause wrong symlinks, which breaks storage management tools that rely
   on enclosure topology on multipath SAS systems (enterprise storage
   environments).

3. **Important issue**: Yes. Enterprise SAS multipath setups are common
   in production servers. Incorrect enclosure associations can lead to
   operators targeting wrong devices during maintenance.

4. **Small and contained**: Yes. Single file change
   (`drivers/scsi/ses.c`), ~10 meaningful lines changed. The core fix is
   replacing one function call.

5. **No new features**: Correct. Pure bug fix.

6. **Self-contained**: Yes. No dependencies on other patches.
   `ses_enclosure_find_by_addr` is only called from this one site, and
   it's a static function within ses.c.

### Risk Assessment
**Very low risk.** The fix narrows the search scope from all enclosures
to just the relevant one. The matching logic within
`ses_enclosure_find_by_addr` is completely unchanged. The only
behavioral difference is that devices will no longer be incorrectly
associated with enclosures on different hosts.

### Bug Age
The buggy code was introduced in commit `c38c007af04b92` ("[SCSI] ses:
Use vpd information from scsi_device") by Hannes Reinecke in v3.15-rc1
(2014). This bug affects **all** current stable trees.

### Verification

- **git blame** confirmed line 687
  (`enclosure_for_each_device(ses_enclosure_find_by_addr, &efd)`) was
  introduced in commit `c38c007af04b92` (v3.15-rc1)
- **git describe --contains c38c007af04b92** confirmed version:
  `v3.15-rc1~136^2~4`
- **Read of `drivers/misc/enclosure.c:85-101`** confirmed
  `enclosure_for_each_device()` iterates over ALL entries in
  `container_list` (global list of all enclosures)
- **Grep for `ses_enclosure_find_by_addr`** confirmed it is only
  referenced at two locations in ses.c: its definition (line 531) and
  the single call site (line 687) — no other callers exist
- **Grep for `enclosure_for_each_device`** confirmed the SES driver at
  line 687 is the ONLY caller outside of enclosure.c itself — so this
  change has no impact on other subsystems
- **Read of `ses_match_to_enclosure()`** (lines 669-689) confirmed
  `edev` is already passed as a parameter but was ignored in favor of
  global iteration
- **lore.kernel.org search** found the patch was reviewed by Martin K.
  Petersen and included in multiple stable releases (6.1.165, 6.6.128,
  6.12.75, 6.18.16, 6.19.6), indicating broad acceptance

### Conclusion
This is a clear, surgical fix for a real bug affecting enterprise
multipath SAS systems. The bug has existed since v3.15 (2014). The fix
is small, self-contained, obviously correct, low-risk, and has been
reviewed by the SCSI maintainer.

**YES**

 drivers/scsi/ses.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
index 2c61624cb4b03..50e744e891295 100644
--- a/drivers/scsi/ses.c
+++ b/drivers/scsi/ses.c
@@ -529,9 +529,8 @@ struct efd {
 };
 
 static int ses_enclosure_find_by_addr(struct enclosure_device *edev,
-				      void *data)
+				      struct efd *efd)
 {
-	struct efd *efd = data;
 	int i;
 	struct ses_component *scomp;
 
@@ -684,7 +683,7 @@ static void ses_match_to_enclosure(struct enclosure_device *edev,
 	if (efd.addr) {
 		efd.dev = &sdev->sdev_gendev;
 
-		enclosure_for_each_device(ses_enclosure_find_by_addr, &efd);
+		ses_enclosure_find_by_addr(edev, &efd);
 	}
 }
 
-- 
2.51.0


  parent reply	other threads:[~2026-03-05 15:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-05 15:36 [PATCH AUTOSEL 6.19-6.18] scsi: ufs: core: Reset urgent_bkops_lvl to allow runtime PM power mode Sasha Levin
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-5.10] unshare: fix unshare_fs() handling Sasha Levin
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-6.12] drm/amdgpu/vcn5: Add SMU dpm interface type Sasha Levin
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-6.1] wifi: mac80211: set default WMM parameters on all links Sasha Levin
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-5.15] ALSA: usb-audio: Check max frame size for implicit feedback mode, too Sasha Levin
2026-03-05 15:36 ` Sasha Levin [this message]
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-6.6] ASoC: cs42l43: Report insert for exotic peripherals Sasha Levin
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-5.15] ALSA: usb-audio: Avoid implicit feedback mode on DIYINHK USB Audio 2.0 Sasha Levin
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-5.10] ACPI: PM: Save NVS memory on Lenovo G70-35 Sasha Levin
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-5.10] scsi: storvsc: Fix scheduling while atomic on PREEMPT_RT Sasha Levin
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-6.1] ASoC: amd: yc: Add ASUS EXPERTBOOK BM1503CDA to quirk table Sasha Levin
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-5.10] ACPI: OSI: Add DMI quirk for Acer Aspire One D255 Sasha Levin
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-6.18] fs: init flags_valid before calling vfs_fileattr_get Sasha Levin
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-6.6] scsi: ufs: core: Fix possible NULL pointer dereference in ufshcd_add_command_trace() Sasha Levin
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-6.18] perf/core: Fix refcount bug and potential UAF in perf_mmap Sasha Levin
2026-03-05 15:36 ` [PATCH AUTOSEL 6.19-6.6] scsi: ufs: core: Fix shift out of bounds when MAXQ=32 Sasha Levin
2026-03-05 15:37 ` [PATCH AUTOSEL 6.19-5.15] scsi: mpi3mr: Add NULL checks when resetting request and reply queues Sasha Levin
2026-03-05 15:37 ` [PATCH AUTOSEL 6.19-6.12] ALSA: hda/realtek: Fix speaker pop on Star Labs StarFighter 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=20260305153704.106918-6-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=djeffery@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=thenzl@redhat.com \
    /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