* [PATCH v3] nvmet-fc: skip port entry rebinding if already bound to a target port
@ 2026-10-16 16:07 Nguyen Duy Nhat Anh
0 siblings, 0 replies; only message in thread
From: Nguyen Duy Nhat Anh @ 2026-10-16 16:07 UTC (permalink / raw)
To: paul.ely
Cc: nareshgottumukkala83, hch, sagi, kch, linux-nvme, linux-kernel,
Nguyen Duy Nhat Anh, syzbot+be62d4b375542ecebd17
In nvmet_fc_portentry_rebind_tgt(), nvmet_fc_tgtlock serializes access to
nvmet_fc_portentry_list, but does not prevent multiple concurrent or
duplicate target port registrations from attempting to rebind to an
already-assigned port entry.
When pe->tgtport is non-NULL, WARN_ON() is triggered and pe->tgtport is
overwritten, leading to kernel warnings and leaking the reference count
acquired by nvmet_fc_tgtport_get().
Fix this by checking if pe->tgtport is already set before acquiring a
reference count and rebinding. If it is bound, skip the entry to prevent
clobbering existing bindings.
Reported-by: syzbot+be62d4b375542ecebd17@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=be62d4b375542ecebd17
Signed-off-by: Nguyen Duy Nhat Anh <neganhat@gmail.com>
---
v2 -> v3:
- Correctly place pe->tgtport check before nvmet_fc_tgtport_get() to avoid refcount leak.
v1 -> v2:
- Move pe->tgtport check before nvmet_fc_tgtport_get() to avoid refcount leak.
---
---
drivers/nvme/target/fc.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index 1b557775e033..43c5202a82b6 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -1321,10 +1321,13 @@ nvmet_fc_portentry_rebind_tgt(struct nvmet_fc_tgtport *tgtport)
list_for_each_entry(pe, &nvmet_fc_portentry_list, pe_list) {
if (tgtport->fc_target_port.node_name == pe->node_name &&
tgtport->fc_target_port.port_name == pe->port_name) {
+
+ if (pe->tgtport)
+ continue;
+
if (!nvmet_fc_tgtport_get(tgtport))
continue;
- WARN_ON(pe->tgtport);
tgtport->pe = pe;
pe->tgtport = tgtport;
break;
--
2.55.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-16 16:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-16 16:07 [PATCH v3] nvmet-fc: skip port entry rebinding if already bound to a target port Nguyen Duy Nhat Anh
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®