[PATCH] nvmet-fc: skip hostport handling when the LLDD provides no hosthandle
Guixin Liu
kanie at linux.alibaba.com
Fri Nov 20 00:05:40 PST 2026
nvmet_fc_alloc_hostport() returns NULL when the LLDD does not implement
the hosthandle abstraction, but the association lifetime code assumes
an association always has a hostport:
- nvmet_fc_xmt_disconnect_assoc() reads assoc->hostport->invalid
- nvmet_fc_target_assoc_free() drops the hostport reference
unconditionally
- nvmet_fc_invalidate_host() compares assoc->hostport->hosthandle
while scanning the association list
The first and the third dereference were introduced by removing the
NULL checks on the assumption that an association always has a
hostport, and the second by inlining nvmet_fc_free_hostport(), which
dropped the pointer check of the inlined helper. A Create Association
failure on such a transport then crashes the target.
Restore the checks: skip the Disconnect Association exchange, skip the
hostport reference drop (there is no reference to balance, the
association never took one), and skip hosthandle matching in the
invalidation scan.
Fixes: 50b474e1faff5 ("nvmet-fc: remove null hostport pointer check")
Fixes: 88517565b5929 ("nvmet-fc: inline nvmet_fc_free_hostport")
Cc: stable at vger.kernel.org
Signed-off-by: Guixin Liu <kanie at linux.alibaba.com>
---
drivers/nvme/target/fc.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index 5d6c1c79508a..3fb4f5b318fe 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -481,6 +481,8 @@ nvmet_fc_xmt_disconnect_assoc(struct nvmet_fc_tgt_assoc *assoc)
* message is normal. Otherwise, send unless the hostport has
* already been invalidated by the lldd.
*/
+ if (!assoc->hostport)
+ return;
if (!tgtport->ops->ls_req || assoc->hostport->invalid)
return;
@@ -1183,7 +1185,8 @@ nvmet_fc_target_assoc_free(struct kref *ref)
/* Send Disconnect now that all i/o has completed */
nvmet_fc_xmt_disconnect_assoc(assoc);
- nvmet_fc_hostport_put(assoc->hostport);
+ if (assoc->hostport)
+ nvmet_fc_hostport_put(assoc->hostport);
spin_lock_irqsave(&tgtport->lock, flags);
oldls = assoc->rcv_disconn;
spin_unlock_irqrestore(&tgtport->lock, flags);
@@ -1533,7 +1536,8 @@ nvmet_fc_invalidate_host(struct nvmet_fc_target_port *target_port,
spin_lock_irqsave(&tgtport->lock, flags);
list_for_each_entry_safe(assoc, next,
&tgtport->assoc_list, a_list) {
- if (assoc->hostport->hosthandle != hosthandle)
+ if (!assoc->hostport ||
+ assoc->hostport->hosthandle != hosthandle)
continue;
if (!nvmet_fc_tgt_a_get(assoc))
continue;
--
2.43.7
More information about the Linux-nvme
mailing list