public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme: prevent double free in nvme_alloc_ns() error handling
@ 2020-04-27 12:34 Niklas Cassel
  2020-04-27 15:06 ` Christoph Hellwig
  2020-04-27 18:03 ` Javier González
  0 siblings, 2 replies; 7+ messages in thread
From: Niklas Cassel @ 2020-04-27 12:34 UTC (permalink / raw)
  To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	Igor Konopko, Matias Bjørling, Javier González
  Cc: Niklas Cassel, Jens Axboe, linux-nvme, linux-kernel

When jumping to the out_put_disk label, we will call put_disk(), which will
trigger a call to disk_release(), which calls blk_put_queue().

Later in the cleanup code, we do blk_cleanup_queue(), which will also call
blk_put_queue().

Putting the queue twice is incorrect, and will generate a KASAN splat.

Set the disk->queue pointer to NULL, before calling put_disk(), so that the
first call to blk_put_queue() will not free the queue.

The second call to blk_put_queue() uses another pointer to the same queue,
so this call will still free the queue.

Fixes: 85136c010285 ("lightnvm: simplify geometry enumeration")
Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
---
 drivers/nvme/host/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 91c1bd659947..f2adea96b04c 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3642,6 +3642,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 
 	return;
  out_put_disk:
+	/* prevent double queue cleanup */
+	ns->disk->queue = NULL;
 	put_disk(ns->disk);
  out_unlink_ns:
 	mutex_lock(&ctrl->subsys->lock);
-- 
2.25.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-04-28 10:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-27 12:34 [PATCH] nvme: prevent double free in nvme_alloc_ns() error handling Niklas Cassel
2020-04-27 15:06 ` Christoph Hellwig
2020-04-27 18:03 ` Javier González
2020-04-27 18:22   ` Niklas Cassel
2020-04-28  7:06     ` Javier González
2020-04-28  7:49       ` Niklas Cassel
2020-04-28 10:32         ` Javier González

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox