nvmet-fc: skip port entry rebinding if already bound to a target port
Subsystems (3)
PATCH 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.
--- drivers/nvme/target/fc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvme/target/fc.c +3 -1
@@ -1324,7 +1324,9 @@ nvmet_fc_portentry_rebind_tgt(struct nvmet_fc_tgtport *tgtport)if (!nvmet_fc_tgtport_get (tgtport))continue ; -WARN_ON (pe->tgtport); +if (pe->tgtport) +continue ; + tgtport->pe = pe; pe->tgtport = tgtport;break ;
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] nvme-target/fc: reference count leak of tgtport on rebind conflict --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] nvme-target/fc: reference count leak of tgtport on rebind conflict --
commit 69be6b42e2f6eef3ebd6d221309e5ccb64969922
Author: Nguyen Duy Nhat Anh <[email protected]>
nvmet-fc: skip port entry rebinding if already bound to a target port
This commit adds a check to avoid clobbering existing target port assignments during rebinding. It prevents multiple concurrent or duplicate target port registrations from overwriting an already-assigned port entry.
drivers/nvme/target/fc.c nvmet_fc_portentry_rebind_tgt(struct nvmet_fc_tgtport *tgtport) · line 1329
Quoted 12 lines
drivers/nvme/target/fc.c +3
-1@@ -1324,7 +1324,9 @@ nvmet_fc_portentry_rebind_tgt(struct nvmet_fc_tgtport *tgtport)if (!nvmet_fc_tgtport_get (tgtport))continue ; -WARN_ON (pe->tgtport); +if (pe->tgtport) +continue ; +
[Severity: Medium]
Does this code leak the reference count on the target port?
The commit message states the intent to check for an existing assignment before acquiring the reference count, but the check is placed immediately after nvmet_fc_tgtport_get() has already incremented the reference.
If pe->tgtport is already set, the continue statement will move to the next iteration without releasing the reference acquired by nvmet_fc_tgtport_get(), permanently leaking it and preventing the target port from being freed upon unregistration.
Quoted 3 lines
drivers/nvme/target/fc.c +0
-0tgtport->pe = pe; pe->tgtport = tgtport;break ;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1