mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Serhat Kumral <serhatkumral1@gmail.com>
To: njavali@marvell.com, GR-QLogic-Storage-Upstream@marvell.com
Cc: James.Bottomley@HansenPartnership.com, mkp@kernel.org,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Serhat Kumral <serhatkumral1@gmail.com>
Subject: [PATCH] scsi: qla2xxx: Fix fcport handling in session creation race
Date: Wed,  7 Oct 2026 13:26:32 +0300	[thread overview]
Message-ID: <20261007102632.11971-1-serhatkumral1@gmail.com> (raw)

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


                 reply	other threads:[~2026-10-07 10:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261007102632.11971-1-serhatkumral1@gmail.com \
    --to=serhatkumral1@gmail.com \
    --cc=GR-QLogic-Storage-Upstream@marvell.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --cc=njavali@marvell.com \
    /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

all inboxes | Powered by JetHome®