* [PATCH v2] nvme: avoid NULL pointer dereference in admin queue initialization error path
@ 2022-04-22 14:40 Smith, Kyle Miller (Nimble Kernel)
2022-04-22 19:01 ` Chaitanya Kulkarni
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Smith, Kyle Miller (Nimble Kernel) @ 2022-04-22 14:40 UTC (permalink / raw)
To: linux-nvme
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>
---
v1 -> v2:
- Update commit message
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)) {
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] nvme: avoid NULL pointer dereference in admin queue initialization error path
2022-04-22 14:40 [PATCH v2] nvme: avoid NULL pointer dereference in admin queue initialization error path Smith, Kyle Miller (Nimble Kernel)
@ 2022-04-22 19:01 ` Chaitanya Kulkarni
2022-04-24 11:40 ` Hannes Reinecke
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2022-04-22 19:01 UTC (permalink / raw)
To: linux-nvme
On 4/22/22 07:40, 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 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>
> ---
Looks good.
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
-ck
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] nvme: avoid NULL pointer dereference in admin queue initialization error path
2022-04-22 14:40 [PATCH v2] nvme: avoid NULL pointer dereference in admin queue initialization error path Smith, Kyle Miller (Nimble Kernel)
2022-04-22 19:01 ` Chaitanya Kulkarni
@ 2022-04-24 11:40 ` Hannes Reinecke
2022-04-26 14:23 ` Sagi Grimberg
2022-04-28 15:11 ` Christoph Hellwig
3 siblings, 0 replies; 5+ messages in thread
From: Hannes Reinecke @ 2022-04-24 11:40 UTC (permalink / raw)
To: Smith, Kyle Miller (Nimble Kernel), linux-nvme
On 4/22/22 16:40, 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 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>
> ---
> v1 -> v2:
> - Update commit message
>
> 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)) {
>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] nvme: avoid NULL pointer dereference in admin queue initialization error path
2022-04-22 14:40 [PATCH v2] nvme: avoid NULL pointer dereference in admin queue initialization error path Smith, Kyle Miller (Nimble Kernel)
2022-04-22 19:01 ` Chaitanya Kulkarni
2022-04-24 11:40 ` Hannes Reinecke
@ 2022-04-26 14:23 ` Sagi Grimberg
2022-04-28 15:11 ` Christoph Hellwig
3 siblings, 0 replies; 5+ messages in thread
From: Sagi Grimberg @ 2022-04-26 14:23 UTC (permalink / raw)
To: Smith, Kyle Miller (Nimble Kernel), linux-nvme
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] nvme: avoid NULL pointer dereference in admin queue initialization error path
2022-04-22 14:40 [PATCH v2] nvme: avoid NULL pointer dereference in admin queue initialization error path Smith, Kyle Miller (Nimble Kernel)
` (2 preceding siblings ...)
2022-04-26 14:23 ` Sagi Grimberg
@ 2022-04-28 15:11 ` Christoph Hellwig
3 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2022-04-28 15:11 UTC (permalink / raw)
To: Smith, Kyle Miller (Nimble Kernel); +Cc: linux-nvme
Thanks,
applied to nvme-5.18.
(with a slightly shortened subject line)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-04-28 15:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-22 14:40 [PATCH v2] nvme: avoid NULL pointer dereference in admin queue initialization error path Smith, Kyle Miller (Nimble Kernel)
2022-04-22 19:01 ` Chaitanya Kulkarni
2022-04-24 11:40 ` Hannes Reinecke
2022-04-26 14:23 ` Sagi Grimberg
2022-04-28 15:11 ` Christoph Hellwig
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.