* [PATCH] scsi: qla2xxx: Fix fcport handling in session creation race
@ 2026-10-07 10:26 Serhat Kumral
0 siblings, 0 replies; only message in thread
From: Serhat Kumral @ 2026-10-07 10:26 UTC (permalink / raw)
To: njavali, GR-QLogic-Storage-Upstream
Cc: James.Bottomley, mkp, linux-scsi, linux-kernel, Serhat Kumral
When a second WWPN lookup finds an existing fcport due to a race, the
driver continues using the newly allocated fcport instead of the existing
one, then frees it at the end of qla24xx_create_new_sess().
Smatch reports a use-after-free of pla in the trailing cleanup.
qlt_plogi_ack_unref() may have already freed pla, making the subsequent
list_del() and kmem_cache_free() invalid.
Fix this by switching to the existing fcport, freeing the
redundant newly allocated one, and removing the trailing cleanup.
Fixes: b5d1531260b9 ("scsi: qla2xxx: Fix slow mem alloc behind lock")
Assisted-by: LLM
Signed-off-by: Serhat Kumral <serhatkumral1@gmail.com>
---
smatch output:
- drivers/scsi/qla2xxx/qla_os.c:5627 qla24xx_create_new_sess() error: dereferencing freed memory 'pla' (line 5573)
drivers/scsi/qla2xxx/qla_os.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 3c412c7fb6fe..1231265365af 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -5456,9 +5456,9 @@ void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
{
unsigned long flags;
fc_port_t *fcport = NULL, *tfcp;
+ fc_port_t *conflict_fcport = NULL;
struct qlt_plogi_ack_t *pla =
(struct qlt_plogi_ack_t *)e->u.new_sess.pla;
- uint8_t free_fcport = 0;
ql_dbg(ql_dbg_disc, vha, 0xffff,
"%s %d %8phC enter\n",
@@ -5529,7 +5529,9 @@ void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
__func__, tfcp->port_name, tfcp->disc_state,
tfcp->fw_login_state);
- free_fcport = 1;
+ conflict_fcport = fcport;
+ fcport = tfcp;
+
} else {
list_add_tail(&fcport->list, &vha->vp_fcports);
@@ -5542,6 +5544,9 @@ void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
}
spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
+ if (conflict_fcport)
+ qla2x00_free_fcport(conflict_fcport);
+
if (fcport) {
fcport->id_changed = 1;
fcport->scan_state = QLA_FCPORT_FOUND;
@@ -5620,14 +5625,6 @@ void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
}
}
}
-
- if (free_fcport) {
- qla2x00_free_fcport(fcport);
- if (pla) {
- list_del(&pla->list);
- kmem_cache_free(qla_tgt_plogi_cachep, pla);
- }
- }
}
static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
--
2.53.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-07 10:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-07 10:26 [PATCH] scsi: qla2xxx: Fix fcport handling in session creation race Serhat Kumral
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®