[PATCH] nvme: avoid NULL pointer dereference in admin queue initialization error path

Keith Busch kbusch at kernel.org
Thu Apr 21 12:00:50 PDT 2022


On Thu, Apr 21, 2022 at 06:05:56PM +0000, Smith, Kyle Miller (Nimble Kernel) wrote:
> 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 for immediately after the call. However, when we return the error 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 <mailto:kyles at hpe.com>

The code change looks fine, but your email client has mangled your patch: the
tabs are not preserved, the commit message doesn't wrap at 75 columnns (see
Documentation/process/submitting-patches.rst), and your sign-off has an
unnecessary 'mailto' prefix.

> ---
> drivers/nvme/host/pci.c | 1 +
> 1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index 6a99ed680915..2f7510938b18 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -1772,6 +1772,7 @@ static int nvme_alloc_admin_tags(struct nvme_dev *dev)
>                                dev->ctrl.admin_q = blk_mq_init_queue(&dev->admin_tagset);
>                                if (IS_ERR(dev->ctrl.admin_q)) {
>                                                blk_mq_free_tag_set(&dev->admin_tagset);
> +                                             dev->ctrl.admin_q = NULL;
>                                                return -ENOMEM;
>                                }
>                                if (!blk_get_queue(dev->ctrl.admin_q)) {
> 
> 
> 



More information about the Linux-nvme mailing list