mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
To: Justin Tee <justin.tee@broadcom.com>,
	Paul Ely <paul.ely@broadcom.com>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	"Martin K. Petersen" <mkp@kernel.org>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] scsi: lpfc: Fix potential VMID resource leak during vport cleanup
Date: Fri, 13 Nov 2026 22:03:49 +0800	[thread overview]
Message-ID: <20261113-4e14e563a1-scsi-lpfc@mail.sdu.edu.cn> (raw)

lpfc_vmid_vport_cleanup() frees the VMID array without freeing the
per-CPU timestamps owned by its entries. It also traverses the embedded
hash nodes after freeing the array.

Free the timestamps in every slot, including those retained after VMID
reinitialization, and clear the hash table before freeing the array.
Clear last_io_time when registration fails so cleanup cannot free it
again.

This issue was found by our static analysis tool under development.

Fixes: 5e633302ace1 ("scsi: lpfc: vmid: Add support for VMID in mailbox command")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/scsi/lpfc/lpfc_scsi.c | 11 +++++------
 drivers/scsi/lpfc/lpfc_vmid.c |  1 +
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 3f39cc065029..75c5b4bfd0f5 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -5475,20 +5475,19 @@ static enum scsi_qc_status lpfc_queuecommand(struct Scsi_Host *shost,
  */
 void lpfc_vmid_vport_cleanup(struct lpfc_vport *vport)
 {
-	u32 bucket;
-	struct lpfc_vmid *cur;
+	u32 i;
 
 	if (vport->port_type == LPFC_PHYSICAL_PORT)
 		timer_delete_sync(&vport->phba->inactive_vmid_poll);
 
 	kfree(vport->qfpa_res);
 	kfree(vport->vmid_priority.vmid_range);
+	if (vport->vmid)
+		for (i = 0; i < vport->max_vmid; i++)
+			free_percpu(vport->vmid[i].last_io_time);
+	hash_init(vport->hash_table);
 	kfree(vport->vmid);
 
-	if (!hash_empty(vport->hash_table))
-		hash_for_each(vport->hash_table, bucket, cur, hnode)
-			hash_del(&cur->hnode);
-
 	vport->qfpa_res = NULL;
 	vport->vmid_priority.vmid_range = NULL;
 	vport->vmid = NULL;
diff --git a/drivers/scsi/lpfc/lpfc_vmid.c b/drivers/scsi/lpfc/lpfc_vmid.c
index 14dbfe954e42..a13e5a07e818 100644
--- a/drivers/scsi/lpfc/lpfc_vmid.c
+++ b/drivers/scsi/lpfc/lpfc_vmid.c
@@ -270,6 +270,7 @@ int lpfc_vmid_get_appid(struct lpfc_vport *vport, char *uuid,
 			hash_del(&vmp->hnode);
 			vmp->flag = LPFC_VMID_SLOT_FREE;
 			free_percpu(vmp->last_io_time);
+			vmp->last_io_time = NULL;
 			write_unlock(&vport->vmid_lock);
 			return -EIO;
 		}

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
-- 
2.43.0


                 reply	other threads:[~2026-11-13 14:04 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=20261113-4e14e563a1-scsi-lpfc@mail.sdu.edu.cn \
    --to=liguangshuo@mail.sdu.edu.cn \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=justin.tee@broadcom.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --cc=paul.ely@broadcom.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®