* [PATCH v2 1/7] scsi: qla2xxx: Check FCE state under fce_mutex in debugfs release
2026-11-03 12:31 [PATCH v2 0/7] scsi: qla2xxx: Fix races, leaks and inverted logic found in review Daniel Wagner
@ 2026-11-03 12:31 ` Daniel Wagner
2026-11-03 12:31 ` [PATCH v2 2/7] scsi: qla2xxx: Don't clear SF_SCANNING of a running fabric scan Daniel Wagner
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Daniel Wagner @ 2026-11-03 12:31 UTC (permalink / raw)
To: Nilesh Javali, GR-QLogic-Storage-Upstream, Martin K. Petersen,
Himanshu Madhani, Quinn Tran
Cc: linux-scsi, Daniel Wagner, stable
qla2x00_dfs_fce_release() tests ha->flags.fce_enabled and ha->fce
before taking fce_mutex. Since commit 841df27d619e ("scsi: qla2xxx:
Move FCE Trace buffer allocation to user control") the buffer can be
freed at runtime by writing 0 to the fce debugfs file, which clears
ha->fce under fce_mutex.
If that write runs between the unlocked check and mutex_lock() in
release, release goes on to memset(ha->fce, ...) with ha->fce == NULL:
CPU0 (close) CPU1 (echo 0 > fce)
!ha->fce -> false
mutex_lock(&ha->fce_mutex)
qla2x00_free_fce_trace()
ha->fce = NULL
mutex_unlock(&ha->fce_mutex)
mutex_lock(&ha->fce_mutex)
memset(NULL, 0, ...)
Move the check under fce_mutex.
Fixes: 841df27d619e ("scsi: qla2xxx: Move FCE Trace buffer allocation to user control")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
drivers/scsi/qla2xxx/qla_dfs.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/qla2xxx/qla_dfs.c b/drivers/scsi/qla2xxx/qla_dfs.c
index 5d08bdbcf70a..247174a38d94 100644
--- a/drivers/scsi/qla2xxx/qla_dfs.c
+++ b/drivers/scsi/qla2xxx/qla_dfs.c
@@ -464,11 +464,11 @@ qla2x00_dfs_fce_release(struct inode *inode, struct file *file)
struct qla_hw_data *ha = vha->hw;
int rval;
- if (ha->flags.fce_enabled || !ha->fce)
- goto out;
-
mutex_lock(&ha->fce_mutex);
+ if (ha->flags.fce_enabled || !ha->fce)
+ goto unlock;
+
/* Re-enable FCE tracing. */
ha->flags.fce_enabled = 1;
memset(ha->fce, 0, fce_calc_size(ha->fce_bufs));
@@ -480,8 +480,8 @@ qla2x00_dfs_fce_release(struct inode *inode, struct file *file)
ha->flags.fce_enabled = 0;
}
+unlock:
mutex_unlock(&ha->fce_mutex);
-out:
return single_release(inode, file);
}
--
2.56.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v2 2/7] scsi: qla2xxx: Don't clear SF_SCANNING of a running fabric scan
2026-11-03 12:31 [PATCH v2 0/7] scsi: qla2xxx: Fix races, leaks and inverted logic found in review Daniel Wagner
2026-11-03 12:31 ` [PATCH v2 1/7] scsi: qla2xxx: Check FCE state under fce_mutex in debugfs release Daniel Wagner
@ 2026-11-03 12:31 ` Daniel Wagner
2026-11-03 12:31 ` [PATCH v2 3/7] scsi: qla2xxx: Fix use-after-free on late bsg completion Daniel Wagner
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Daniel Wagner @ 2026-11-03 12:31 UTC (permalink / raw)
To: Nilesh Javali, GR-QLogic-Storage-Upstream, Martin K. Petersen,
Himanshu Madhani, Quinn Tran
Cc: linux-scsi, Daniel Wagner, stable
Commit 7adbd2b78090 ("scsi: qla2xxx: Free sp in error path to fix
system crash") changed the "scan active" early exit in
qla_fab_async_scan() from a plain return to a jump to done_free_sp.
Besides freeing sp, that label also clears SF_SCANNING and, if no other
scan flag is set, queues scan_work again. Both belong to the scan that
is still in flight, not to the caller that bailed out:
- SF_SCANNING is dropped while the GPN_FT/GNN_FT command is still
outstanding, so the next qla_fab_async_scan() call starts a second
scan that resets vha->scan.step and clears vha->scan.l under the
running one.
- qla2x00_wait_for_hba_ready() stops waiting for the scan.
This also happens for sp == NULL, e.g. when the DPC thread calls
qla_fab_scan_start() during a running scan.
Only release the sp handed in and leave the scan state alone.
Fixes: 7adbd2b78090 ("scsi: qla2xxx: Free sp in error path to fix system crash")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
drivers/scsi/qla2xxx/qla_gs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
index 20b1aef455c4..d5ea22f01772 100644
--- a/drivers/scsi/qla2xxx/qla_gs.c
+++ b/drivers/scsi/qla2xxx/qla_gs.c
@@ -3621,7 +3621,9 @@ int qla_fab_async_scan(scsi_qla_host_t *vha, srb_t *sp)
spin_unlock_irqrestore(&vha->work_lock, flags);
ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x2012,
"%s: scan active for sp:%p\n", __func__, sp);
- goto done_free_sp;
+ if (sp)
+ qla24xx_sp_unmap(vha, sp);
+ return rval;
}
vha->scan.scan_flags |= SF_SCANNING;
if (!sp)
--
2.56.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v2 3/7] scsi: qla2xxx: Fix use-after-free on late bsg completion
2026-11-03 12:31 [PATCH v2 0/7] scsi: qla2xxx: Fix races, leaks and inverted logic found in review Daniel Wagner
2026-11-03 12:31 ` [PATCH v2 1/7] scsi: qla2xxx: Check FCE state under fce_mutex in debugfs release Daniel Wagner
2026-11-03 12:31 ` [PATCH v2 2/7] scsi: qla2xxx: Don't clear SF_SCANNING of a running fabric scan Daniel Wagner
@ 2026-11-03 12:31 ` Daniel Wagner
2026-11-03 12:31 ` [PATCH v2 4/7] scsi: qla2xxx: target: Fix cmd release on CDB allocation failure Daniel Wagner
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Daniel Wagner @ 2026-11-03 12:31 UTC (permalink / raw)
To: Nilesh Javali, GR-QLogic-Storage-Upstream, Martin K. Petersen,
Himanshu Madhani, Quinn Tran
Cc: linux-scsi, Daniel Wagner, stable
When the abort in qla_bsg_found() times out, the outstanding command
slot is checked again under the qpair lock before the sp is released.
The check only bails out if the slot holds a different bsg job:
if (req->outstanding_cmds[cnt] &&
req->outstanding_cmds[cnt]->u.bsg_job != bsg_job)
If the firmware completes the command between the timeout and taking
the lock, qla2x00_get_sp_from_handle() has already cleared the slot
and qla2x00_bsg_job_done() has dropped the INIT reference and completed
the bsg job. The slot is NULL, the check falls through, and
qla_bsg_found() writes to the freed sp, drops the reference a second
time and calls bsg_job_done() again.
Bail out unless the slot still holds our sp.
Fixes: c423263082ee ("scsi: qla2xxx: Fix abort in bsg timeout")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
drivers/scsi/qla2xxx/qla_bsg.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index ab559048dbb8..8565f4e838f9 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -3669,11 +3669,11 @@ static bool qla_bsg_found(struct qla_qpair *qpair, struct bsg_job *bsg_job)
spin_lock_irqsave(qpair->qp_lock_ptr, flags);
/*
- * recheck to make sure it's still the same bsg_job due to
- * qp_lock_ptr was released earlier.
+ * recheck to make sure it's still the same sp due to
+ * qp_lock_ptr was released earlier. If the slot is empty or
+ * reused, fw has completed the sp and freed it.
*/
- if (req->outstanding_cmds[cnt] &&
- req->outstanding_cmds[cnt]->u.bsg_job != bsg_job) {
+ if (req->outstanding_cmds[cnt] != sp) {
/* fw had returned the bsg */
spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
return true;
--
2.56.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v2 4/7] scsi: qla2xxx: target: Fix cmd release on CDB allocation failure
2026-11-03 12:31 [PATCH v2 0/7] scsi: qla2xxx: Fix races, leaks and inverted logic found in review Daniel Wagner
` (2 preceding siblings ...)
2026-11-03 12:31 ` [PATCH v2 3/7] scsi: qla2xxx: Fix use-after-free on late bsg completion Daniel Wagner
@ 2026-11-03 12:31 ` Daniel Wagner
2026-11-03 12:31 ` [PATCH v2 5/7] scsi: qla2xxx: Fix inverted IRQ_NO_BALANCING toggling around PCI reset Daniel Wagner
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Daniel Wagner @ 2026-11-03 12:31 UTC (permalink / raw)
To: Nilesh Javali, GR-QLogic-Storage-Upstream, Martin K. Petersen,
Himanshu Madhani, Quinn Tran
Cc: linux-scsi, Daniel Wagner, stable
If the extra CDB buffer cannot be allocated, qlt_get_tag() releases
the command with tgt_ops->free_cmd(). For tcm_qla2xxx that queues
transport_generic_free_cmd() on a se_cmd that was never initialized
by the target core: its cmd_kref is zero, so the put underflows the
refcount and the command is never released. The session tag is
leaked, and so is the num_pend_cmds increment done earlier in
qlt_get_tag(). Once enough commands have leaked, every new command is
answered with BUSY.
Undo exactly what qlt_get_tag() has done so far, the same way the
qlt_do_work() error path handles a command that never reached the
target core: drop num_pend_cmds and return the tag with rel_cmd().
Fixes: 091719c21d5a ("scsi: qla2xxx: target: Fix invalid memory access with big CDBs")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
drivers/scsi/qla2xxx/qla_target.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index 431a59d499b3..939b5e9f8471 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -4660,7 +4660,8 @@ static struct qla_tgt_cmd *qlt_get_tag(scsi_qla_host_t *vha,
cdb = kmalloc(cdb_len, GFP_ATOMIC);
if (unlikely(!cdb)) {
- vha->hw->tgt.tgt_ops->free_cmd(cmd);
+ qlt_decr_num_pend_cmds(vha);
+ vha->hw->tgt.tgt_ops->rel_cmd(cmd);
return NULL;
}
/* CAUTION: copy CDB from atio not cmd->atio */
--
2.56.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v2 5/7] scsi: qla2xxx: Fix inverted IRQ_NO_BALANCING toggling around PCI reset
2026-11-03 12:31 [PATCH v2 0/7] scsi: qla2xxx: Fix races, leaks and inverted logic found in review Daniel Wagner
` (3 preceding siblings ...)
2026-11-03 12:31 ` [PATCH v2 4/7] scsi: qla2xxx: target: Fix cmd release on CDB allocation failure Daniel Wagner
@ 2026-11-03 12:31 ` Daniel Wagner
2026-11-03 12:31 ` [PATCH v2 6/7] scsi: qla2xxx: Reject unsolicited NVMe LS from ports without NVMe rport Daniel Wagner
2026-11-21 2:32 ` [PATCH v2 0/7] scsi: qla2xxx: Fix races, leaks and inverted logic found in review Martin K. Petersen
6 siblings, 0 replies; 8+ messages in thread
From: Daniel Wagner @ 2026-11-03 12:31 UTC (permalink / raw)
To: Nilesh Javali, GR-QLogic-Storage-Upstream, Martin K. Petersen,
Himanshu Madhani, Quinn Tran
Cc: linux-scsi, Daniel Wagner, stable
qla2xxx_set_affinity_nobalance(pdev, true) sets IRQ_NO_BALANCING and
false clears it. The PCI error handlers call it the wrong way round:
qla2xxx_pci_error_detected() clears the flag before the reset and
qla2xxx_pci_slot_reset() sets it afterwards. So irqbalance can still
touch the MSI-X vectors during EEH recovery, which is the failure the
commit set out to fix, and IRQ balancing stays disabled for good after
a successful recovery.
Set the flag in error_detected and clear it in slot_reset, as the
commit message and the kernel-doc describe and as the ipr driver does
in commit 6ac3484fb13b ("scsi: ipr: Enable/disable IRQD_NO_BALANCING
during reset").
Fixes: eaea513077cd ("scsi: qla2xxx: Enable/disable IRQD_NO_BALANCING during reset")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
drivers/scsi/qla2xxx/qla_os.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 3c412c7fb6fe..93103d7e4e28 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -8009,7 +8009,7 @@ qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
goto out;
}
- qla2xxx_set_affinity_nobalance(pdev, false);
+ qla2xxx_set_affinity_nobalance(pdev, true);
switch (state) {
case pci_channel_io_normal:
@@ -8147,7 +8147,7 @@ qla2xxx_pci_slot_reset(struct pci_dev *pdev)
ql_dbg(ql_dbg_aer, base_vha, 0x900e,
"Slot Reset returning %x.\n", ret);
- qla2xxx_set_affinity_nobalance(pdev, true);
+ qla2xxx_set_affinity_nobalance(pdev, false);
return ret;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v2 6/7] scsi: qla2xxx: Reject unsolicited NVMe LS from ports without NVMe rport
2026-11-03 12:31 [PATCH v2 0/7] scsi: qla2xxx: Fix races, leaks and inverted logic found in review Daniel Wagner
` (4 preceding siblings ...)
2026-11-03 12:31 ` [PATCH v2 5/7] scsi: qla2xxx: Fix inverted IRQ_NO_BALANCING toggling around PCI reset Daniel Wagner
@ 2026-11-03 12:31 ` Daniel Wagner
2026-11-21 2:32 ` [PATCH v2 0/7] scsi: qla2xxx: Fix races, leaks and inverted logic found in review Martin K. Petersen
6 siblings, 0 replies; 8+ messages in thread
From: Daniel Wagner @ 2026-11-03 12:31 UTC (permalink / raw)
To: Nilesh Javali, GR-QLogic-Storage-Upstream, Martin K. Petersen,
Himanshu Madhani, Quinn Tran
Cc: linux-scsi, Daniel Wagner, stable
qla2xxx_process_purls_iocb() looks up the fcport for the S_ID of an
unsolicited NVMe LS request and dereferences its nvme_remote_port
without checking it. The pointer is NULL for an fcport that is known
to the driver but not registered with the NVMe-FC transport, e.g. an
FCP-only port, a port whose NVMe registration has not finished yet,
or one that qla_nvme_remoteport_delete() has already cleared. An LS
request from such a port crashes the response queue handler in
interrupt context.
Reject the request with an invalid association reason, the same as for
an unknown S_ID.
Fixes: 875386b98857 ("scsi: qla2xxx: Add Unsolicited LS Request and Response Support for NVMe")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
drivers/scsi/qla2xxx/qla_nvme.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index beccece1e7d9..8d27cdf58755 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -1419,6 +1419,15 @@ void qla2xxx_process_purls_iocb(void **pkt, struct rsp_que **rsp)
goto out;
}
rport = fcport->nvme_remote_port;
+ if (!rport) {
+ ql_dbg(ql_dbg_unsol, vha, 0x2113,
+ "No NVMe remote port for sid=%06x did=%06x\n",
+ id.b24, d_id.b24);
+ a.reason = FCNVME_RJT_RC_INV_ASSOC;
+ a.explanation = FCNVME_RJT_EXP_NONE;
+ xmt_reject = true;
+ goto out;
+ }
qla_rport = rport->private;
item = qla27xx_copy_multiple_pkt(vha, pkt, rsp, true, false);
--
2.56.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 0/7] scsi: qla2xxx: Fix races, leaks and inverted logic found in review
2026-11-03 12:31 [PATCH v2 0/7] scsi: qla2xxx: Fix races, leaks and inverted logic found in review Daniel Wagner
` (5 preceding siblings ...)
2026-11-03 12:31 ` [PATCH v2 6/7] scsi: qla2xxx: Reject unsolicited NVMe LS from ports without NVMe rport Daniel Wagner
@ 2026-11-21 2:32 ` Martin K. Petersen
6 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2026-11-21 2:32 UTC (permalink / raw)
To: Daniel Wagner
Cc: Nilesh Javali, GR-QLogic-Storage-Upstream, Martin K. Petersen,
Himanshu Madhani, Quinn Tran, linux-scsi, stable
Daniel,
> A review of recent qla2xxx changes turned up a handful of bugs in
> commits that are already upstream and partly marked for stable:
Found two regressions:
1. **Patch 3:** SRB address reuse can let the timeout handler remove and
free another BSG job’s command. Retain the job-identity check alongside
the pointer comparison.
2. **Patch 5:** ISP82xx recovery can skip `slot_reset()`, leaving
`IRQ_NO_BALANCING` set after successful recovery.
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 8+ messages in thread