Skip to content

Commit 132be62

Browse files
Niklas CasselChristoph Hellwig
Niklas Cassel
authored and
Christoph Hellwig
committed
nvme: prevent double free in nvme_alloc_ns() error handling
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: 85136c0 ("lightnvm: simplify geometry enumeration") Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent d205bde commit 132be62

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/nvme/host/core.c

+2
Original file line numberDiff line numberDiff line change
@@ -3642,6 +3642,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
36423642

36433643
return;
36443644
out_put_disk:
3645+
/* prevent double queue cleanup */
3646+
ns->disk->queue = NULL;
36453647
put_disk(ns->disk);
36463648
out_unlink_ns:
36473649
mutex_lock(&ctrl->subsys->lock);

0 commit comments

Comments
 (0)