nvmet-fc: skip port entry rebinding if already bound to a target port
Subsystems (3)
PATCH v3 1/1 nvmet-fc: skip port entry rebinding if already bound to a target port
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.
---
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(-)
drivers/nvme/target/fc.c +4 -1
@@ -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 ;
Signature · 1 line
2.55.0