Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Guixin Liu <kanie@linux.alibaba.com>
To: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
	Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	Nilay Shroff <nilay@linux.ibm.com>,
	Daniel Wagner <dwagner@suse.de>, Hannes Reinecke <hare@suse.de>
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH] nvmet-fc: skip hostport handling when the LLDD provides no hosthandle
Date: Fri, 20 Nov 2026 16:05:40 +0800	[thread overview]
Message-ID: <20261120080540.1177154-1-kanie@linux.alibaba.com> (raw)

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



             reply	other threads:[~2026-11-20  8:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  8:05 Guixin Liu [this message]
2026-11-20 17:21 ` [PATCH] nvmet-fc: skip hostport handling when the LLDD provides no hosthandle Christoph Hellwig
2026-11-20 19:54 ` Keith Busch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120080540.1177154-1-kanie@linux.alibaba.com \
    --to=kanie@linux.alibaba.com \
    --cc=axboe@kernel.dk \
    --cc=dwagner@suse.de \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=nilay@linux.ibm.com \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox