nvmet-tcp: fix possible memory leak when tearing down a controller
authorSagi Grimberg <sagi@grimberg.me>
Sun, 28 Apr 2024 08:49:49 +0000 (11:49 +0300)
committerKeith Busch <kbusch@kernel.org>
Wed, 1 May 2024 09:58:42 +0000 (02:58 -0700)
commit6825bdde44340c5a9121f6d6fa25cc885bd9e821
treef6befdcb21b78f331b741f4663a3c54efefb41c7
parent25bb3534ee21e39eb9301c4edd7182eb83cb0d07
nvmet-tcp: fix possible memory leak when tearing down a controller

When we teardown the controller, we wait for pending I/Os to complete
(sq->ref on all queues to drop to zero) and then we go over the commands,
and free their command buffers in case they are still fetching data from
the host (e.g. processing nvme writes) and have yet to take a reference
on the sq.

However, we may miss the case where commands have failed before executing
and are queued for sending a response, but will never occur because the
queue socket is already down. In this case we may miss deallocating command
buffers.

Solve this by freeing all commands buffers as nvmet_tcp_free_cmd_buffers is
idempotent anyways.

Reported-by: Yi Zhang <yi.zhang@redhat.com>
Tested-by: Yi Zhang <yi.zhang@redhat.com>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
drivers/nvme/target/tcp.c