[PATCH] nvme-tcp: fix use-after-free in nvme_tcp_free_ctrl()

Nilay Shroff nilay at linux.ibm.com
Fri Oct 30 10:43:37 PDT 2026


On 10/30/26 10:31 PM, Christian Aurich Zanettini Martins wrote:
> nvme_tcp_free_ctrl() reads ctrl->ctrl.opts to know how many queue
> mutexes to destroy. When creating the controller fails,
> nvmf_create_ctrl() frees opts as soon as nvme_tcp_create_ctrl()
> returns, but a concurrent open of the character device can hold the
> last reference to the controller. With CONFIG_DEBUG_KOBJECT_RELEASE,
> which delays the release, every failed connect reads freed memory:
> 
>    BUG: KASAN: slab-use-after-free in nvme_tcp_free_ctrl+0x38b/0x430
>    Read of size 4 at addr ffff888005b93740 by task kworker/2:1/51
> 
> Keep the size of the queue array in the controller and use it instead.
> 
> Fixes: 2eeeaa9c1ff0 ("nvme-tcp: Validate the queue state under the queue lock in the address attribute")
> Cc:stable at vger.kernel.org
> Signed-off-by: Christian Aurich Zanettini Martins<christian.aurichzm at gmail.com>

Looks good to me:
Reviewed-by: Nilay Shroff <nilay at linux.ibm.com>



More information about the Linux-nvme mailing list