* [PATCH] nvmet-fc: skip hostport handling when the LLDD provides no hosthandle
@ 2026-11-20 8:05 Guixin Liu
2026-11-20 17:21 ` Christoph Hellwig
2026-11-20 19:54 ` Keith Busch
0 siblings, 2 replies; 3+ messages in thread
From: Guixin Liu @ 2026-11-20 8:05 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Nilay Shroff, Daniel Wagner, Hannes Reinecke
Cc: linux-nvme
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@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] nvmet-fc: skip hostport handling when the LLDD provides no hosthandle
2026-11-20 8:05 [PATCH] nvmet-fc: skip hostport handling when the LLDD provides no hosthandle Guixin Liu
@ 2026-11-20 17:21 ` Christoph Hellwig
2026-11-20 19:54 ` Keith Busch
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2026-11-20 17:21 UTC (permalink / raw)
To: Guixin Liu
Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Nilay Shroff, Daniel Wagner, Hannes Reinecke, linux-nvme
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] nvmet-fc: skip hostport handling when the LLDD provides no hosthandle
2026-11-20 8:05 [PATCH] nvmet-fc: skip hostport handling when the LLDD provides no hosthandle Guixin Liu
2026-11-20 17:21 ` Christoph Hellwig
@ 2026-11-20 19:54 ` Keith Busch
1 sibling, 0 replies; 3+ messages in thread
From: Keith Busch @ 2026-11-20 19:54 UTC (permalink / raw)
To: Jens Axboe, Christoph Hellwig, Sagi Grimberg, Nilay Shroff,
Daniel Wagner, Hannes Reinecke, Guixin Liu
Cc: linux-nvme
On Fri, 20 Nov 2026 16:05:40 +0800, Guixin Liu wrote:
> 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
>
> [...]
Thanks, applied to nvme-7.4.
[1/1] nvmet-fc: skip hostport handling when the LLDD provides no hosthandle
commit: 65f2f49bd912d446f93f840303e90283142ed15b
--
Keith Busch <kbusch@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-20 19:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 8:05 [PATCH] nvmet-fc: skip hostport handling when the LLDD provides no hosthandle Guixin Liu
2026-11-20 17:21 ` Christoph Hellwig
2026-11-20 19:54 ` Keith Busch
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.