* [PATCH 0/9] scsi: fix missing locking and dump length checks in several drivers
@ 2026-12-05 6:32 Praneeth Balasubramanian
2026-12-05 6:32 ` [PATCH 1/9] scsi: bnx2i: Hold the session back_lock around iscsi_itt_to_task() Praneeth Balasubramanian
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:32 UTC (permalink / raw)
To: Nilesh Javali, Manish Rangankar, GR-ETH-Storage-Upstream,
James E.J. Bottomley, Martin K. Petersen, Sathya Prakash,
Sreekanth Reddy, Suganath Prabu Subramani, Ranjan Kumar,
Brian King, Russell King, Satish Kharat, Sesidhar Baddela,
Karan Tilak Kumar, GR-QLogic-Storage-Upstream
Cc: Praneeth Balasubramanian, linux-scsi, linux-kernel,
MPT-FusionLinux.pdl, linux-arm-kernel, target-devel
These 9 patches fix bugs that an LLM-based audit found. The audit checks
code against the rules stated in kernel comments, such as "the caller
must hold this lock" or "drop the reference when done". Each changelog
explains the rule and the path that breaks it.
The patches are independent of each other, and each one can be applied
on its own. They are against next-20261204 and also apply to mainline
(007722b8211f), except patch 3, which needs linux-next.
None of them was runtime-tested. There is no reproducer, and I do not
have the hardware. Each one builds without new warnings with W=1, and
checkpatch.pl is clean. Details are below the --- of each patch.
Tools: GLM-5.3 drafted the fixes and changelogs. Claude Opus 5.5 checked
each one against the source and rewrote parts where needed. I reviewed
every patch.
Praneeth Balasubramanian (9):
scsi: bnx2i: Hold the session back_lock around iscsi_itt_to_task()
scsi: mpt3sas: do not keep an enclosure pointer across a host reset
scsi: pmcraid: Take host_lock around scsi_report_bus_reset()
scsi: ipr: Skip dump entries whose length is not a 4 byte multiple
scsi: arm: Fix eh_abort race against the interrupt handler
scsi: csiostor: hold hw lock when issuing port stats mailbox command
scsi: fnic: Hold fnic_lock for the oxid calls in the FIP timer work
scsi: qla2xxx: Hold qp_lock when completing command in abort timeout
scsi: target: core: Fix PRgeneration race in REGISTER AND MOVE
drivers/scsi/arm/fas216.c | 11 ++++++--
drivers/scsi/bnx2i/bnx2i_hwi.c | 11 ++++----
drivers/scsi/csiostor/csio_lnode.c | 3 +++
drivers/scsi/fnic/fip.c | 7 +++++
drivers/scsi/ipr.c | 3 ++-
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 38 +++++++++++++++++-----------
drivers/scsi/pmcraid.c | 13 +++++++++-
drivers/scsi/qla2xxx/qla_init.c | 6 +++--
drivers/target/target_core_pr.c | 9 +------
9 files changed, 66 insertions(+), 35 deletions(-)
base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
--
2.25.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/9] scsi: bnx2i: Hold the session back_lock around iscsi_itt_to_task()
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 ` Praneeth Balasubramanian
2026-12-05 6:32 ` [PATCH 2/9] scsi: mpt3sas: do not keep an enclosure pointer across a host reset Praneeth Balasubramanian
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:32 UTC (permalink / raw)
To: Nilesh Javali, Manish Rangankar, GR-ETH-Storage-Upstream,
James E.J. Bottomley, Martin K. Petersen
Cc: Praneeth Balasubramanian, stable, linux-scsi, linux-kernel
bnx2i_send_iscsi_tmf() looks up the task to abort with
iscsi_itt_to_task(), then reads ctask->sc and the command's data
direction. iscsi_itt_to_task() requires the session back_lock, but
bnx2i holds only the frwd_lock here. A TODO comment and an
__assume_ctx_lock() annotation mark the gap.
The completion path runs under back_lock. It clears task->sc and
completes the command. If it runs between the !ctask->sc check and the
ref_sc load, ref_sc is NULL and the data direction read faults.
Take back_lock around the lookup and the two reads. libiscsi already
nests back_lock inside frwd_lock, so the lock order does not change.
Remove the TODO and the annotation.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: 659743b02c41 ("[SCSI] libiscsi: Reduce locking contention in fast path")
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 and
checked against the source 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 the lock context annotations for SCSI
added the TODO. In mainline the same lookup has no TODO and
iscsi_itt_to_task() takes (conn, itt). The fix is the same there.
drivers/scsi/bnx2i/bnx2i_hwi.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c b/drivers/scsi/bnx2i/bnx2i_hwi.c
index c22f1c981d02..70bc5e5f9b8b 100644
--- a/drivers/scsi/bnx2i/bnx2i_hwi.c
+++ b/drivers/scsi/bnx2i/bnx2i_hwi.c
@@ -405,13 +405,10 @@ int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
switch (tmfabort_hdr->flags & ISCSI_FLAG_TM_FUNC_MASK) {
case ISCSI_TM_FUNC_ABORT_TASK:
case ISCSI_TM_FUNC_TASK_REASSIGN:
- /*
- * TODO: hold session->back_lock around the iscsi_itt_to_task()
- * call below.
- */
- __assume_ctx_lock(&session->back_lock);
+ spin_lock_bh(&session->back_lock);
ctask = iscsi_itt_to_task(session, conn, tmfabort_hdr->rtt);
- if (!ctask || !ctask->sc)
+ if (!ctask || !ctask->sc) {
+ spin_unlock_bh(&session->back_lock);
/*
* the iscsi layer must have completed the cmd while
* was starting up.
@@ -421,6 +418,7 @@ int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
* In this case, the task must be aborted
*/
return 0;
+ }
ref_sc = ctask->sc;
if (ref_sc->sc_data_direction == DMA_TO_DEVICE)
@@ -429,6 +427,7 @@ int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
else
dword = (ISCSI_TASK_TYPE_READ <<
ISCSI_CMD_REQUEST_TYPE_SHIFT);
+ spin_unlock_bh(&session->back_lock);
tmfabort_wqe->ref_itt = (dword |
(tmfabort_hdr->rtt & ISCSI_ITT_MASK));
break;
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/9] scsi: mpt3sas: do not keep an enclosure pointer across a host reset
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 ` Praneeth Balasubramanian
2026-12-05 6:32 ` [PATCH 3/9] scsi: pmcraid: Take host_lock around scsi_report_bus_reset() Praneeth Balasubramanian
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:32 UTC (permalink / raw)
To: Sathya Prakash, Sreekanth Reddy, Suganath Prabu Subramani,
Ranjan Kumar, James E.J. Bottomley, Martin K. Petersen
Cc: Praneeth Balasubramanian, stable, MPT-FusionLinux.pdl, linux-scsi,
linux-kernel
_scsih_add_device() looks up the enclosure node of the new device and
keeps the pointer. Later it reads the node again: in the "device not
ready" message after _scsih_wait_for_target_to_become_ready(), and when
it fills in the enclosure logical ID and chassis slot of the new
sas_device. In between, it sleeps in the readiness wait, in kzalloc()
and in the config page request of _scsih_get_sas_address().
A host reset frees every enclosure node and builds the list again in
_scsih_create_enclosure_list_after_reset(). The reset can be issued by
the readiness wait itself, when a SCSI command and then the target
reset for it time out. It can also come from another context, such as
the fault watchdog. _scsih_fw_event_cleanup_queue() does not wait for
the running firmware event, so _scsih_add_device() keeps running and
then reads freed memory.
Copy the enclosure logical ID and chassis slot right after the lookup
and use the copies later, as _scsih_pcie_add_device() does by reading
them at lookup time.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: aee682fad6cd ("scsi: mpt3sas: Improve device discovery and readiness handling for slow devices")
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.
Jeff Layton's mpt3sas series (v5, 2026-11-30) rewrites the firmware
event handling in mpt3sas_scsih.c but not the enclosure lookup. If it
lands first, this patch may need a rebase.
Before aee682fad6cd the pointer was also kept across kzalloc() and the
config page request in _scsih_get_sas_address(), but no readiness wait.
So the window existed since 22a923c315ba ("scsi: mpt3sas: Cache
enclosure pages during enclosure add.") and became much wider with the
readiness wait. The patch applies only on top of aee682fad6cd.
The enclosure list has no lock. The kernel-doc of
mpt3sas_scsih_enclosure_find_by_handle() says the caller should hold
ioc->sas_device_lock, but neither the reset path that frees the list nor
the event that adds to it takes that lock. Other lookups use the node
right away without sleeping, so this patch only fixes the one pointer
that is kept across sleeps.
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 38 +++++++++++++++++-----------
1 file changed, 23 insertions(+), 15 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 04255286a2a6..6b1d05385bb1 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -8409,6 +8409,9 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 retry_count,
struct _sas_device *sas_device;
struct _enclosure_node *enclosure_dev = NULL;
enum device_responsive_state rc;
+ u64 enclosure_logical_id = 0;
+ u8 is_chassis_slot_valid = 0;
+ u8 chassis_slot = 0;
u32 ioc_status;
u64 sas_address;
u32 device_info;
@@ -8463,9 +8466,23 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 retry_count,
enclosure_dev =
mpt3sas_scsih_enclosure_find_by_handle(ioc,
le16_to_cpu(sas_device_pg0.EnclosureHandle));
- if (enclosure_dev == NULL)
+ if (enclosure_dev == NULL) {
ioc_info(ioc, "Enclosure handle(0x%04x) doesn't match with enclosure device!\n",
sas_device_pg0.EnclosureHandle);
+ } else {
+ /*
+ * A host reset frees the enclosure list and can run
+ * while this function sleeps below. Copy the fields
+ * instead of keeping a pointer to the node.
+ */
+ enclosure_logical_id =
+ le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
+ if (le16_to_cpu(enclosure_dev->pg0.Flags) &
+ MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
+ is_chassis_slot_valid = 1;
+ chassis_slot = enclosure_dev->pg0.ChassisSlot;
+ }
+ }
}
/*
@@ -8497,10 +8514,9 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 retry_count,
sas_device_pg0.EnclosureLevel, connector_name));
}
- if ((enclosure_dev) && (le16_to_cpu(enclosure_dev->pg0.Flags) &
- MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID))
+ if (is_chassis_slot_valid)
ioc_info(ioc, "chassis slot(0x%04x)\n",
- enclosure_dev->pg0.ChassisSlot);
+ chassis_slot);
if (rc == DEVICE_RETRY || rc == DEVICE_START_UNIT ||
rc == DEVICE_STOP_UNIT || rc == DEVICE_RETRY_UA)
@@ -8553,17 +8569,9 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 retry_count,
sas_device->connector_name[0] = '\0';
}
/* get enclosure_logical_id & chassis_slot*/
- sas_device->is_chassis_slot_valid = 0;
- if (enclosure_dev) {
- sas_device->enclosure_logical_id =
- le64_to_cpu(enclosure_dev->pg0.EnclosureLogicalID);
- if (le16_to_cpu(enclosure_dev->pg0.Flags) &
- MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) {
- sas_device->is_chassis_slot_valid = 1;
- sas_device->chassis_slot =
- enclosure_dev->pg0.ChassisSlot;
- }
- }
+ sas_device->enclosure_logical_id = enclosure_logical_id;
+ sas_device->is_chassis_slot_valid = is_chassis_slot_valid;
+ sas_device->chassis_slot = chassis_slot;
/* get device name */
sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/9] scsi: pmcraid: Take host_lock around scsi_report_bus_reset()
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
2026-12-05 6:32 ` [PATCH 4/9] scsi: ipr: Skip dump entries whose length is not a 4 byte multiple Praneeth Balasubramanian
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:32 UTC (permalink / raw)
To: James E.J. Bottomley, Martin K. Petersen
Cc: Praneeth Balasubramanian, stable, linux-scsi, linux-kernel
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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/9] scsi: ipr: Skip dump entries whose length is not a 4 byte multiple
2026-12-05 6:32 [PATCH 0/9] scsi: fix missing locking and dump length checks in several drivers Praneeth Balasubramanian
` (2 preceding siblings ...)
2026-12-05 6:32 ` [PATCH 3/9] scsi: pmcraid: Take host_lock around scsi_report_bus_reset() Praneeth Balasubramanian
@ 2026-12-05 6:32 ` Praneeth Balasubramanian
2026-12-05 6:32 ` [PATCH 5/9] scsi: arm: Fix eh_abort race against the interrupt handler Praneeth Balasubramanian
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:32 UTC (permalink / raw)
To: Brian King, James E.J. Bottomley, Martin K. Petersen
Cc: Praneeth Balasubramanian, stable, linux-scsi, linux-kernel
ipr_get_ioa_dump() takes each dump entry length from the adapter dump
table and passes it to ipr_sdt_copy() without checking that it is a
multiple of 4. ipr_sdt_copy() copies whole 32 bit words but advances
page_offset, bytes_copied and the dump header length by the full byte
count. When firmware supplies an unaligned length the trailing 1 to 3
bytes of the copy stay uninitialized and the next entry is written at a
shifted offset. A later read of the dump sysfs attribute then copies
those uninitialized kmalloc bytes to userspace. The dump is only
readable by root and the values come from firmware, so the impact is
limited.
Skip such entries by clearing their valid flag, matching the existing
handling of entries whose length exceeds the maximum dump size.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
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 and
checked against the source 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.
drivers/scsi/ipr.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 1a5e362cccbd..71a70ce59bb2 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -3173,7 +3173,8 @@ static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
valid = 0;
}
if (valid) {
- if (bytes_to_copy > max_dump_size) {
+ if (bytes_to_copy > max_dump_size ||
+ bytes_to_copy & (sizeof(u32) - 1)) {
sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
continue;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/9] scsi: arm: Fix eh_abort race against the interrupt handler
2026-12-05 6:32 [PATCH 0/9] scsi: fix missing locking and dump length checks in several drivers Praneeth Balasubramanian
` (3 preceding siblings ...)
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 ` Praneeth Balasubramanian
2026-12-05 6:32 ` [PATCH 6/9] scsi: csiostor: hold hw lock when issuing port stats mailbox command Praneeth Balasubramanian
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:32 UTC (permalink / raw)
To: Russell King, James E.J. Bottomley, Martin K. Petersen
Cc: Praneeth Balasubramanian, stable, linux-arm-kernel, linux-scsi,
linux-kernel
fas216_eh_abort() calls fas216_find_command() with no lock held and
interrupts enabled. fas216_find_command() checks whether the command is
disconnectable and clears info->SCpnt in separate steps. If the device
interrupt fires in between, fas216_reselected_intr() restores the
disconnectable command and puts the bus into PHASE_MSGIN. The abort then
stores NULL into info->SCpnt while the target is reconnected. The next
target-driven interrupt ends in fas216_done() with no current command,
which panics the kernel.
fas216_intr() itself takes no lock. These boards are single processor, so
taking host_lock with irqs disabled serializes the abort against the
interrupt handler. This matches what the bus and host reset handlers
already do.
Hold host_lock with irqs disabled around the fas216_find_command() call.
It only removes commands from the driver queues, clears a bit and prints,
so it is safe to call in atomic context. Update the stale comment about
io_request_lock and disabled irqs as well.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
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 and
checked against the source 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; arm
rpc_defconfig, GCC 8.5), clang 23 unless noted. checkpatch.pl is clean.
Not runtime-tested, and there is no reproducer. I do not have this
hardware.
These boards are uniprocessor ARM (RiscPC). Compile-tested with
rpc_defconfig and the Acorn SCSI drivers as modules, using the
kernel.org GCC 8.5 cross compiler (the platform needs GCC older than
9.1).
drivers/scsi/arm/fas216.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/arm/fas216.c b/drivers/scsi/arm/fas216.c
index d0752c0bf425..7626f5102bf4 100644
--- a/drivers/scsi/arm/fas216.c
+++ b/drivers/scsi/arm/fas216.c
@@ -2422,11 +2422,14 @@ static enum res_find fas216_find_command(FAS216_Info *info,
*
* Abort this command.
* Returns: FAILED if unable to abort
- * Notes: io_request_lock is taken, and irqs are disabled
+ * Notes: the host lock is taken with irqs disabled while looking
+ * for the command
*/
int fas216_eh_abort(struct scsi_cmnd *SCpnt)
{
FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
+ unsigned long flags;
+ enum res_find res;
int result = FAILED;
fas216_checkmagic(info);
@@ -2438,7 +2441,11 @@ int fas216_eh_abort(struct scsi_cmnd *SCpnt)
print_debug_list();
fas216_dumpstate(info);
- switch (fas216_find_command(info, SCpnt)) {
+ spin_lock_irqsave(&info->host_lock, flags);
+ res = fas216_find_command(info, SCpnt);
+ spin_unlock_irqrestore(&info->host_lock, flags);
+
+ switch (res) {
/*
* We found the command, and cleared it out. Either
* the command is still known to be executing on the
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6/9] scsi: csiostor: hold hw lock when issuing port stats mailbox command
2026-12-05 6:32 [PATCH 0/9] scsi: fix missing locking and dump length checks in several drivers Praneeth Balasubramanian
` (4 preceding siblings ...)
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 ` 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
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:32 UTC (permalink / raw)
To: James E.J. Bottomley, Martin K. Petersen
Cc: Praneeth Balasubramanian, stable, linux-scsi, linux-kernel
csio_get_phy_port_stats() calls csio_mb_issue() without holding
hw->lock. The comment above csio_mb_issue() says that the caller should
hold the hw lock, and the other mailbox users in the driver do. If
another thread uses the mailbox at the same time, the two commands can
interfere with each other. The path is reached through csio_get_stats()
from the fc_host statistics attributes in sysfs, which every user can
read.
Take hw->lock around the csio_mb_issue() call in
csio_get_phy_port_stats(). This matches the locking of the other sysfs
handlers in csio_attr.c. csio_mb_issue() polls with mdelay() instead of
sleeping, so it is safe to call under spin_lock_irq().
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: a3667aaed569 ("[SCSI] csiostor: Chelsio FCoE offload driver")
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 and
checked against the source 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.
drivers/scsi/csiostor/csio_lnode.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/scsi/csiostor/csio_lnode.c b/drivers/scsi/csiostor/csio_lnode.c
index 161973957976..7fef0882862f 100644
--- a/drivers/scsi/csiostor/csio_lnode.c
+++ b/drivers/scsi/csiostor/csio_lnode.c
@@ -1408,11 +1408,14 @@ csio_get_phy_port_stats(struct csio_hw *hw, uint8_t portid,
portparams.nstats = 4;
csio_fcoe_read_portparams_init_mb(hw, mbp, CSIO_MB_DEFAULT_TMO,
&portparams, NULL);
+ spin_lock_irq(&hw->lock);
if (csio_mb_issue(hw, mbp)) {
csio_err(hw, "Issue of FCoE port params failed!\n");
mempool_free(mbp, hw->mb_mempool);
+ spin_unlock_irq(&hw->lock);
return -EINVAL;
}
+ spin_unlock_irq(&hw->lock);
csio_mb_process_portparams_rsp(hw, mbp, &retval,
&portparams, port_stats);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 7/9] scsi: fnic: Hold fnic_lock for the oxid calls in the FIP timer work
2026-12-05 6:32 [PATCH 0/9] scsi: fix missing locking and dump length checks in several drivers Praneeth Balasubramanian
` (5 preceding siblings ...)
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 ` 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
8 siblings, 0 replies; 10+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:32 UTC (permalink / raw)
To: Satish Kharat, Sesidhar Baddela, Karan Tilak Kumar,
James E.J. Bottomley, Martin K. Petersen
Cc: Praneeth Balasubramanian, stable, linux-scsi, linux-kernel
fdls_alloc_oxid() and fdls_schedule_oxid_free() must be called with
fnic->fnic_lock held. Both assert it with lockdep_assert_held(). The
oxid bitmap and the oxid reclaim list they update are also changed by
fdls_reclaim_oxid_handler() and by the frame receive path, which hold
the lock.
fnic_work_on_fip_timer() runs on fnic_fip_queue without the lock. On a
FLOGI timeout it calls fdls_schedule_oxid_free(), and through
fnic_fcoe_start_flogi() it calls fdls_alloc_oxid(). With lockdep
enabled, both calls trigger the assertion. Without lockdep, the list_add
can race with the list_del and kfree in the reclaim handler.
Take fnic_lock around the two calls. The rest of the timer work is left
as it is: fnic_vlan_discovery_timeout() takes the lock itself, and the
frame send does not need it.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: 098585aa8aca ("scsi: fnic: Add and integrate support for FIP")
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.
drivers/scsi/fnic/fip.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/scsi/fnic/fip.c b/drivers/scsi/fnic/fip.c
index 8f44abfc01a5..e9d4fe9777ab 100644
--- a/drivers/scsi/fnic/fip.c
+++ b/drivers/scsi/fnic/fip.c
@@ -353,6 +353,7 @@ void fnic_fcoe_start_flogi(struct fnic *fnic)
u64 flogi_tov;
uint16_t oxid;
uint16_t frame_size = sizeof(struct fip_flogi);
+ unsigned long flags;
frame = fdls_alloc_frame(iport);
if (frame == NULL) {
@@ -406,8 +407,10 @@ void fnic_fcoe_start_flogi(struct fnic *fnic)
memcpy(pflogi_req->eth.h_dest, iport->selected_fcf.fcf_mac,
ETH_ALEN);
+ spin_lock_irqsave(&fnic->fnic_lock, flags);
oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_FLOGI,
&iport->active_oxid_fabric_req);
+ spin_unlock_irqrestore(&fnic->fnic_lock, flags);
if (oxid == FNIC_UNASSIGNED_OXID) {
FNIC_FCS_DBG(KERN_INFO, fnic,
"Failed to allocate OXID to send FIP FLOGI");
@@ -752,7 +755,11 @@ void fnic_work_on_fip_timer(struct work_struct *work)
fnic_vlan_discovery_timeout(fnic);
}
} else if (iport->fip.state == FDLS_FIP_FLOGI_STARTED) {
+ unsigned long flags;
+
+ spin_lock_irqsave(&fnic->fnic_lock, flags);
fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
+ spin_unlock_irqrestore(&fnic->fnic_lock, flags);
FNIC_FIP_DBG(KERN_INFO, fnic,
"FLOGI timeout\n");
if (iport->fip.flogi_retry < fnic->config.flogi_retries)
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 8/9] scsi: qla2xxx: Hold qp_lock when completing command in abort timeout
2026-12-05 6:32 [PATCH 0/9] scsi: fix missing locking and dump length checks in several drivers Praneeth Balasubramanian
` (6 preceding siblings ...)
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 ` Praneeth Balasubramanian
2026-12-05 6:32 ` [PATCH 9/9] scsi: target: core: Fix PRgeneration race in REGISTER AND MOVE Praneeth Balasubramanian
8 siblings, 0 replies; 10+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:32 UTC (permalink / raw)
To: Nilesh Javali, GR-QLogic-Storage-Upstream, James E.J. Bottomley,
Martin K. Petersen
Cc: Praneeth Balasubramanian, stable, linux-scsi, linux-kernel
qla24xx_abort_iocb_timeout() removes the original command from the
outstanding command array under qpair->qp_lock_ptr, then drops the lock
before calling sp->cmd_sp->done(). The done callback completes and frees
the original command, which ends in qla2x00_sp_free_dma() or
qla2xxx_qpair_sp_free_dma() and their qla_put_buf() call.
qla_put_buf() must run under qp_lock_ptr, as its comment and
lockdep_assert_held() state, so on this path the buffer is returned to
the pool without the lock.
The unlocked qla_put_buf() can race qla_get_buf() on the same qpair. The
pool accounting is then updated non-atomically, and qla_trim_buf() can
dma_pool_free() a buffer that qla_get_buf() has just handed to a new
EDIF command, which is then submitted using the freed buffer. This
affects the EDIF buffer pool only and needs a firmware abort timeout to
trigger.
Call sp->cmd_sp->done() before dropping qp_lock_ptr, so the completion
chain runs under the same lock as the interrupt completion path, which
already invokes this callback with the lock held. qla2x00_abort_srb
calls done under the lock as well, and no done or free path takes the
qp lock itself, so no new lock ordering is introduced. The abort srb
itself never takes a pool buffer, so its own completion stays outside
the lock.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: 71c80b75ce8f ("scsi: qla2xxx: Do command completion on abort timeout")
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 and
checked against the source 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.
drivers/scsi/qla2xxx/qla_init.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index ccb039d97353..3d80ead06aa1 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -139,15 +139,17 @@ static void qla24xx_abort_iocb_timeout(void *data)
break;
}
}
- spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
-
if (cmdsp_found && sp->cmd_sp) {
/*
* This done function should take care of
* original command ref: INIT
+ *
+ * The completion path ends in qla_put_buf(), which
+ * must run under qp_lock.
*/
sp->cmd_sp->done(sp->cmd_sp, QLA_OS_TIMER_EXPIRED);
}
+ spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
if (sp_found) {
abt->u.abt.comp_status = cpu_to_le16(CS_TIMEOUT);
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 9/9] scsi: target: core: Fix PRgeneration race in REGISTER AND MOVE
2026-12-05 6:32 [PATCH 0/9] scsi: fix missing locking and dump length checks in several drivers Praneeth Balasubramanian
` (7 preceding siblings ...)
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 ` Praneeth Balasubramanian
8 siblings, 0 replies; 10+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:32 UTC (permalink / raw)
To: Martin K. Petersen
Cc: Praneeth Balasubramanian, stable, linux-scsi, target-devel,
linux-kernel
__core_scsi3_add_registration() increments dev->t10_pr.pr_generation
with no lock held when it runs for a REGISTER AND MOVE. The old comment
says dev_reservation_lock is already held in that case. That is not
true. core_scsi3_emulate_pro_register_and_move() drops the lock before
calling core_scsi3_alloc_registration() because the allocation can
sleep. It only takes it back afterwards.
The unlocked increment can race with core_scsi3_pr_generation(), which
updates the same counter under dev_reservation_lock for a plain
REGISTER. Both updates can read the same value and one increment is
lost. READ KEYS then reports an incorrect PRgeneration. The effect is
functional only and it takes a remote initiator to trigger it.
Always take the generation from core_scsi3_pr_generation() and drop the
register_move special case along with the stale comment. No caller of
__core_scsi3_add_registration() holds dev_reservation_lock here. The
register_move=0 path in the same function already calls
core_scsi3_pr_generation() in this spot, so taking the lock cannot
deadlock.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: c66ac9db8d4a ("[SCSI] target: Add LIO target core v4.0.0-rc6")
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 and
checked against the source 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 did not write a reproducer.
drivers/target/target_core_pr.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 0f2ff9d42150..3283fa5ee298 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -1095,15 +1095,8 @@ static void __core_scsi3_add_registration(
/*
* Increment PRgeneration counter for struct se_device upon a successful
* REGISTER, see spc4r17 section 6.3.2 READ_KEYS service action
- *
- * Also, when register_move = 1 for PROUT REGISTER_AND_MOVE service
- * action, the struct se_device->dev_reservation_lock will already be held,
- * so we do not call core_scsi3_pr_generation() which grabs the lock
- * for the REGISTER.
*/
- pr_reg->pr_res_generation = (register_move) ?
- dev->t10_pr.pr_generation++ :
- core_scsi3_pr_generation(dev);
+ pr_reg->pr_res_generation = core_scsi3_pr_generation(dev);
spin_lock(&pr_tmpl->registration_lock);
list_add_tail(&pr_reg->pr_reg_list, &pr_tmpl->registration_list);
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-12-05 6:33 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 3/9] scsi: pmcraid: Take host_lock around scsi_report_bus_reset() Praneeth Balasubramanian
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox