* [PATCH] scsi: lpfc: Look up the VMID entry under vmid_lock
@ 2026-11-16 2:39 Changyul Lee
2026-11-16 3:01 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Changyul Lee @ 2026-11-16 2:39 UTC (permalink / raw)
To: Justin Tee, Paul Ely
Cc: Martin K . Petersen, James E . J . Bottomley, Hannes Reinecke,
Nigel Kirkland, linux-scsi, linux-kernel, Changyul Lee
lpfc_cmpl_ct_cmd_vmid() looks up the VMID entry for an RAPP_IDENT
response without vport->vmid_lock and takes the lock only after the
lookup. lpfc_vmid_get_appid() can meanwhile hash_del() another entry
from the same bucket under the lock. hash_del() clears the next pointer
of the removed node, so the walk stops early and misses the entry that
waits for the response. That entry keeps LPFC_VMID_REQ_REGISTER, and
the I/O of that VM is sent without a VMID tag from then on.
Take vmid_lock before the lookup, as lpfc_vmid_get_appid() does.
Fixes: 33c79741deaf ("scsi: lpfc: vmid: Introduce VMID in I/O path")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
Found with a static analysis tool we are developing.
Compile-tested only, with x86_64_defconfig plus SCSI_LPFC and W=1.
drivers/scsi/lpfc/lpfc_ct.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
index f709e5087577..af720ccdf1b6 100644
--- a/drivers/scsi/lpfc/lpfc_ct.c
+++ b/drivers/scsi/lpfc/lpfc_ct.c
@@ -3613,14 +3613,13 @@ lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
hash = lpfc_vmid_hash_fn(app->obj.entity_id,
app->obj.entity_id_len);
+ write_lock(&vport->vmid_lock);
vmp = lpfc_get_vmid_from_hashtable(vport, hash,
app->obj.entity_id);
if (vmp) {
- write_lock(&vport->vmid_lock);
vmp->un.app_id = be32_to_cpu(app->app_id);
vmp->flag |= LPFC_VMID_REGISTERED;
vmp->flag &= ~LPFC_VMID_REQ_REGISTER;
- write_unlock(&vport->vmid_lock);
/* Set IN USE flag */
vport->vmid_flag |= LPFC_VMID_IN_USE;
} else {
@@ -3628,6 +3627,7 @@ lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
"6901 No entry found %s hash %d\n",
app->obj.entity_id, hash);
}
+ write_unlock(&vport->vmid_lock);
break;
case SLI_CTAS_DAPP_IDENT:
app = (struct app_id_object *)(DAPP_IDENT_OFFSET + data);
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] scsi: lpfc: Look up the VMID entry under vmid_lock
2026-11-16 2:39 [PATCH] scsi: lpfc: Look up the VMID entry under vmid_lock Changyul Lee
@ 2026-11-16 3:01 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-16 3:01 UTC (permalink / raw)
To: Changyul Lee; +Cc: linux-scsi
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: lpfc: inaccurate Fixes trailer for lpfc_cmpl_ct_cmd_vmid()
lock fix
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] scsi: lpfc: data race and list corruption in
lpfc_cmpl_ct_cmd_vmid() [1]
--
commit ace8e21fd4e560f69d845916087ba204329824c3
Author: Changyul Lee <lcy8047@gmail.com>
> scsi: lpfc: Look up the VMID entry under vmid_lock
>
> lpfc_cmpl_ct_cmd_vmid() looks up the VMID entry for an RAPP_IDENT
> response without vport->vmid_lock and takes the lock only after the
> lookup. lpfc_vmid_get_appid() can meanwhile hash_del() another entry
> from the same bucket under the lock. hash_del() clears the next pointer
> of the removed node, so the walk stops early and misses the entry that
> waits for the response. That entry keeps LPFC_VMID_REQ_REGISTER, and
> the I/O of that VM is sent without a VMID tag from then on.
>
> Take vmid_lock before the lookup, as lpfc_vmid_get_appid() does.
>
> Fixes: 33c79741deaf ("scsi: lpfc: vmid: Introduce VMID in I/O path")
> Signed-off-by: Changyul Lee <lcy8047@gmail.com>
[Severity: Low]
33c79741deaf ("scsi: lpfc: vmid: Introduce VMID in I/O path") only touched
drivers/scsi/lpfc/lpfc_scsi.c. The unlocked lpfc_get_vmid_from_hashtable()
call in lpfc_cmpl_ct_cmd_vmid() was added by 742b0cf87a8f ("scsi: lpfc:
vmid: Implement CT commands for appid"), so should the Fixes tag be:
Fixes: 742b0cf87a8f ("scsi: lpfc: vmid: Implement CT commands for appid")
> diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
> index f709e50875770..af720ccdf1b6f 100644
> --- a/drivers/scsi/lpfc/lpfc_ct.c
> +++ b/drivers/scsi/lpfc/lpfc_ct.c
> @@ -3613,14 +3613,13 @@ lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
>
> hash = lpfc_vmid_hash_fn(app->obj.entity_id,
> app->obj.entity_id_len);
> + write_lock(&vport->vmid_lock);
> vmp = lpfc_get_vmid_from_hashtable(vport, hash,
> app->obj.entity_id);
> if (vmp) {
> - write_lock(&vport->vmid_lock);
> vmp->un.app_id = be32_to_cpu(app->app_id);
> vmp->flag |= LPFC_VMID_REGISTERED;
> vmp->flag &= ~LPFC_VMID_REQ_REGISTER;
> - write_unlock(&vport->vmid_lock);
> /* Set IN USE flag */
> vport->vmid_flag |= LPFC_VMID_IN_USE;
> } else {
> @@ -3628,6 +3627,7 @@ lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
> "6901 No entry found %s hash %d\n",
> app->obj.entity_id, hash);
> }
> + write_unlock(&vport->vmid_lock);
> break;
> case SLI_CTAS_DAPP_IDENT:
> app = (struct app_id_object *)(DAPP_IDENT_OFFSET + data);
[Severity: High]
This problem wasn't introduced by this patch, but the SLI_CTAS_DALLAPP_ID
branch right below in lpfc_cmpl_ct_cmd_vmid() causes a NULL pointer
dereference, list corruption, and a memory leak [1]:
drivers/scsi/lpfc/lpfc_ct.c:lpfc_cmpl_ct_cmd_vmid() {
...
case SLI_CTAS_DALLAPP_ID:
...
read_lock(&vport->vmid_lock);
for (i = 0; i < phba->cfg_max_vmid; i++) {
vmp = &vport->vmid[i];
if (vmp->flag != LPFC_VMID_SLOT_FREE)
memset(vmp, 0, sizeof(struct lpfc_vmid));
}
read_unlock(&vport->vmid_lock);
/* for all elements in the hash table */
if (!hash_empty(vport->hash_table))
hash_for_each(vport->hash_table, bucket, cur, hnode)
hash_del(&cur->hnode);
...
}
Can this crash when deregistering all app IDs? Zeroing vmp with memset()
while its hnode is still linked in vport->hash_table clears hnode.next and
hnode.pprev, so the subsequent hash_del(&cur->hnode) dereferences a NULL
pprev pointer. In addition, the loop mutates vport->vmid under read_lock()
instead of write_lock(), overwrites vmp->last_io_time without calling
free_percpu(), and walks vport->hash_table without holding vport->vmid_lock
or using hash_for_each_safe().
[1] https://sashiko.dev/#/bug/linux-b856b4ae-5c8f-4fb3-812c-1d152bd8d42f
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116023939.588838-1-lcy8047@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 3:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 2:39 [PATCH] scsi: lpfc: Look up the VMID entry under vmid_lock Changyul Lee
2026-11-16 3:01 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox