nvmet-fc: skip hostport handling when the LLDD provides no hosthandle
Subsystems (3)
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.
--- drivers/nvme/target/fc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/nvme/target/fc.c +6 -2
@@ -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
Looks good:
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()readsassoc->hostport->invalid
-nvmet_fc_target_assoc_free()drops the hostport reference unconditionally
-nvmet_fc_invalidate_host()comparesassoc->hostport->hosthandlewhile 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]>