[PATCH] nvmet-fc: skip hostport ops when the LLDD has no host handle

kensanya kensanya at 163.com
Thu Oct 15 04:20:40 PDT 2026


At 2026-10-15 14:14:49, "Christoph Hellwig" <hch at lst.de> wrote:
>On Wed, Oct 14, 2026 at 03:53:03PM +0800, kensanya at 163.com wrote:
>> From: TanZheng <tanzheng at kylinos.cn>
>> 
>> nvmet_fc_alloc_hostport() returns NULL when the LLDD passes a NULL
>> hosthandle. That is not an ERR_PTR, so nvmet_fc_alloc_target_assoc()
>> keeps the association and leaves assoc->hostport NULL.
>
>A NULL hosthandle doesn't make much sense, so why do you want to handle
>that?

Hi.

nvmet_fc_rcv_ls_req() only stores the hosthandle in the iod. It does not call 
nvmet_fc_alloc_hostport(). That function returns NULL for a NULL hosthandle, 
and nvmet_fc_alloc_target_assoc() stores it in assoc->hostport. 
The association is still created, so teardown can NULL-dereference it in nvmet_
fc_hostport_put(), and in nvmet_fc_xmt_disconnect_assoc() when ops->ls_req is set.

nvmet_fc_hostport_put() needs the same check. No hostport is allocated and 
no kref is taken, but nvmet_fc_target_assoc_free() still calls nvmet_fc_hostport_put(assoc->hostport), 
which does kref_put(&hostport->ref, nvmet_fc_hostport_free).

Best regard.
TanZheng.


More information about the Linux-nvme mailing list