[PATCH 3/9] scsi: pmcraid: Take host_lock around scsi_report_bus_reset()

From: Praneeth Balasubramanian

Date: Sat Dec 05 2026 - 01:33:40 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Praneeth Balasubramanian <praneethb2002@xxxxxxxxx>
---

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