]> git.hungrycats.org Git - linux/commitdiff
virtio_blk: fix panic in initialization error path
authorOmar Sandoval <osandov@fb.com>
Mon, 9 Jan 2017 19:44:12 +0000 (11:44 -0800)
committerSasha Levin <alexander.levin@verizon.com>
Sun, 10 Sep 2017 20:36:06 +0000 (16:36 -0400)
[ Upstream commit 6bf6b0aa3da84a3d9126919a94c49c0fb7ee2fb3 ]

If blk_mq_init_queue() returns an error, it gets assigned to
vblk->disk->queue. Then, when we call put_disk(), we end up calling
blk_put_queue() with the ERR_PTR, causing a bad dereference. Fix it by
only assigning to vblk->disk->queue on success.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Reviewed-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
drivers/block/virtio_blk.c

index 5ea2f0bbbc7c3d6e62a016bcce22ff5a8ce46c1b..071c3ea70882195c3721922c541057424f3b9bcd 100644 (file)
@@ -642,11 +642,12 @@ static int virtblk_probe(struct virtio_device *vdev)
        if (err)
                goto out_put_disk;
 
-       q = vblk->disk->queue = blk_mq_init_queue(&vblk->tag_set);
+       q = blk_mq_init_queue(&vblk->tag_set);
        if (IS_ERR(q)) {
                err = -ENOMEM;
                goto out_free_tags;
        }
+       vblk->disk->queue = q;
 
        q->queuedata = vblk;