Skip to contentSkip to conversation

nvmet-fc: skip hostport handling when the LLDD provides no hosthandle

PATCH Applied Guixin Liu 3 participants 3 messages Nov 20

Subsystems (3)
lore
Share & tools
lore

Guixin Liu

author
#0 lore raw

PATCH 1/1 nvmet-fc: skip hostport handling when the LLDD provides no hosthandle

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")
---
 drivers/nvme/target/fc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/nvme/target/fc.c +6 -2
index 5d6c1c79508a..3fb4f5b318fe 100644
@@ -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;
Signature · 1 line
2.43.7
maintainer Applied
#2 lore raw
In reply to Guixin Liu
Quoted 11 lines · Guixin Liu

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 <[email protected]>