nvme: prevent double free in nvme_alloc_ns() error handling
authorNiklas Cassel <niklas.cassel@wdc.com>
Mon, 27 Apr 2020 12:34:41 +0000 (14:34 +0200)
committerChristoph Hellwig <hch@lst.de>
Mon, 27 Apr 2020 15:08:06 +0000 (17:08 +0200)
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>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/core.c

index 91c1bd659947eb259292f01c4f3b86e2ec70cb7f..f2adea96b04cd9605158854dbfe16200b0b63a8b 100644 (file)
@@ -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);