nvme-pci: fix a NULL pointer dereference in nvme_alloc_admin_tags
authorSmith, Kyle Miller (Nimble Kernel) <kyles@hpe.com>
Fri, 22 Apr 2022 14:40:32 +0000 (14:40 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jun 2022 08:22:38 +0000 (10:22 +0200)
commit906c81dba8ee8057523859b5e1a2479e9fd34860
treeb3e3d44f94c2716dda13c86ce912f15880f94397
parent48d32e41bbfe3cfa5a9811e3a1959e628e196391
nvme-pci: fix a NULL pointer dereference in nvme_alloc_admin_tags

[ Upstream commit da42761181627e9bdc37d18368b827948a583929 ]

In nvme_alloc_admin_tags, the admin_q can be set to an error (typically
-ENOMEM) if the blk_mq_init_queue call fails to set up the queue, which
is checked immediately after the call. However, when we return the error
message up the stack, to nvme_reset_work the error takes us to
nvme_remove_dead_ctrl()
  nvme_dev_disable()
   nvme_suspend_queue(&dev->queues[0]).

Here, we only check that the admin_q is non-NULL, rather than not
an error or NULL, and begin quiescing a queue that never existed, leading
to bad / NULL pointer dereference.

Signed-off-by: Kyle Smith <kyles@hpe.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvme/host/pci.c