From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <mkp@kernel.org>
Cc: Praneeth Balasubramanian <praneethb2002@gmail.com>,
stable@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/9] scsi: pmcraid: Take host_lock around scsi_report_bus_reset()
Date: Fri, 4 Dec 2026 22:32:23 -0800 [thread overview]
Message-ID: <20261205063229.2518424-4-praneethb2002@gmail.com> (raw)
In-Reply-To: <20261205063229.2518424-1-praneethb2002@gmail.com>
scsi_report_bus_reset() iterates the host device list with
__shost_for_each_device(). That form of the iterator requires the caller
to hold host_lock. pmcraid calls it from two places without the lock.
pmcraid_handle_error_log() runs in the tasklet completion path.
pmcraid_error_handler() also runs from the tasklet and holds no lock.
Without the lock a concurrent path that removes a device, such as a
configuration change handled by the worker, can free an scsi_device
while the unlocked iteration is on it. That is a use-after-free read.
Add spin_lock_irqsave()/spin_unlock_irqrestore() around
scsi_report_bus_reset() in both pmcraid_handle_error_log() and
pmcraid_error_handler(). The other callers of scsi_report_bus_reset()
in this driver already hold host_lock and are unchanged.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: 89a368104150 ("[SCSI] pmcraid: PMC-Sierra MaxRAID driver to support 6Gb/s SAS RAID controller")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
Notes:
This was found by an LLM-based audit, part of research at UCSB SecLab.
An LLM turned a kernel comment into a rule, and three LLM votes checked
the code against it. The fix and changelog were drafted with GLM-5.3,
then checked against the source and partly rewritten with Claude Opus
5.5. I reviewed the patch and take responsibility for it.
Testing: builds without new warnings with W=1 (x86_64 allmodconfig),
clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
reproducer. I do not have this hardware.
This is against linux-next, where Scsi_Host embeds host_lock. Mainline
still has a pointer there.
drivers/scsi/pmcraid.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 34f10dfc2bd0..85c06103c88d 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -1696,6 +1696,7 @@ static void pmcraid_ioasc_logger(u32 ioasc, struct pmcraid_cmd *cmd)
static void pmcraid_handle_error_log(struct pmcraid_instance *pinstance)
{
struct pmcraid_hcam_ldn *hcam_ldn;
+ unsigned long lock_flags;
u32 ioasc;
hcam_ldn = (struct pmcraid_hcam_ldn *)pinstance->ldn.hcam;
@@ -1724,9 +1725,13 @@ static void pmcraid_handle_error_log(struct pmcraid_instance *pinstance)
ioasc == PMCRAID_IOASC_UA_BUS_WAS_RESET_BY_OTHER) {
dev_info(&pinstance->pdev->dev,
"UnitAttention due to IOA Bus Reset\n");
+ spin_lock_irqsave(&pinstance->host->host_lock,
+ lock_flags);
scsi_report_bus_reset(
pinstance->host,
RES_BUS(hcam_ldn->error_log.fd_ra));
+ spin_unlock_irqrestore(&pinstance->host->host_lock,
+ lock_flags);
}
return;
@@ -2586,6 +2591,7 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
u32 ioasc = le32_to_cpu(ioasa->ioasc);
u32 masked_ioasc = ioasc & PMCRAID_IOASC_SENSE_MASK;
bool sense_copied = false;
+ unsigned long lock_flags;
if (!res) {
pmcraid_info("resource pointer is NULL\n");
@@ -2628,9 +2634,14 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
case PMCRAID_IOASC_UA_BUS_WAS_RESET:
case PMCRAID_IOASC_UA_BUS_WAS_RESET_BY_OTHER:
- if (!res->reset_progress)
+ if (!res->reset_progress) {
+ spin_lock_irqsave(&pinstance->host->host_lock,
+ lock_flags);
scsi_report_bus_reset(pinstance->host,
scsi_cmd->device->channel);
+ spin_unlock_irqrestore(&pinstance->host->host_lock,
+ lock_flags);
+ }
scsi_cmd->result |= (DID_ERROR << 16);
break;
--
2.25.1
next prev parent reply other threads:[~2026-12-05 6:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 6:32 [PATCH 0/9] scsi: fix missing locking and dump length checks in several drivers Praneeth Balasubramanian
2026-12-05 6:32 ` [PATCH 1/9] scsi: bnx2i: Hold the session back_lock around iscsi_itt_to_task() Praneeth Balasubramanian
2026-12-05 6:32 ` [PATCH 2/9] scsi: mpt3sas: do not keep an enclosure pointer across a host reset Praneeth Balasubramanian
2026-12-05 6:32 ` Praneeth Balasubramanian [this message]
2026-12-05 6:32 ` [PATCH 4/9] scsi: ipr: Skip dump entries whose length is not a 4 byte multiple Praneeth Balasubramanian
2026-12-05 6:32 ` [PATCH 5/9] scsi: arm: Fix eh_abort race against the interrupt handler Praneeth Balasubramanian
2026-12-05 6:32 ` [PATCH 6/9] scsi: csiostor: hold hw lock when issuing port stats mailbox command Praneeth Balasubramanian
2026-12-05 6:32 ` [PATCH 7/9] scsi: fnic: Hold fnic_lock for the oxid calls in the FIP timer work Praneeth Balasubramanian
2026-12-05 6:32 ` [PATCH 8/9] scsi: qla2xxx: Hold qp_lock when completing command in abort timeout Praneeth Balasubramanian
2026-12-05 6:32 ` [PATCH 9/9] scsi: target: core: Fix PRgeneration race in REGISTER AND MOVE Praneeth Balasubramanian
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=20261205063229.2518424-4-praneethb2002@gmail.com \
--to=praneethb2002@gmail.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=stable@vger.kernel.org \
/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