]> www.infradead.org Git - nvme.git/commitdiff
nvmet-tcp: fix kernel crash if commands allocation fails
authorMaurizio Lombardi <mlombard@redhat.com>
Wed, 21 Aug 2024 14:28:26 +0000 (16:28 +0200)
committerKeith Busch <kbusch@kernel.org>
Mon, 26 Aug 2024 23:00:52 +0000 (16:00 -0700)
If the commands allocation fails in nvmet_tcp_alloc_cmds()
the kernel crashes in nvmet_tcp_release_queue_work() because of
a NULL pointer dereference.

  nvmet: failed to install queue 0 cntlid 1 ret 6
  Unable to handle kernel NULL pointer dereference at
         virtual address 0000000000000008

Fix the bug by setting queue->nr_cmds to zero in case
nvmet_tcp_alloc_cmd() fails.

Fixes: 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
drivers/nvme/target/tcp.c

index 5bff0d5464d1c9d2f3c3ba286edd6c4a7084ce38..7c51c2a8c109a9c14187d8717349f65a07825bea 100644 (file)
@@ -2146,8 +2146,10 @@ static u16 nvmet_tcp_install_queue(struct nvmet_sq *sq)
        }
 
        queue->nr_cmds = sq->size * 2;
-       if (nvmet_tcp_alloc_cmds(queue))
+       if (nvmet_tcp_alloc_cmds(queue)) {
+               queue->nr_cmds = 0;
                return NVME_SC_INTERNAL;
+       }
        return 0;
 }