Commit 6ae6ff6f authored by Jason Wang's avatar Jason Wang Committed by Michael S. Tsirkin

virtio-blk: validate num_queues during probe

If an untrusted device neogitates BLK_F_MQ but advertises a zero
num_queues, the driver may end up trying to allocating zero size
buffers where ZERO_SIZE_PTR is returned which may pass the checking
against the NULL. This will lead unexpected results.

Fixing this by failing the probe in this case.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
Link: https://lore.kernel.org/r/20211019070152.8236-2-jasowang@redhat.comSigned-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Reviewed-by: default avatarStefano Garzarella <sgarzare@redhat.com>
Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent f1429e6c
...@@ -571,6 +571,10 @@ static int init_vq(struct virtio_blk *vblk) ...@@ -571,6 +571,10 @@ static int init_vq(struct virtio_blk *vblk)
&num_vqs); &num_vqs);
if (err) if (err)
num_vqs = 1; num_vqs = 1;
if (!err && !num_vqs) {
dev_err(&vdev->dev, "MQ advertisted but zero queues reported\n");
return -EINVAL;
}
num_vqs = min_t(unsigned int, num_vqs = min_t(unsigned int,
min_not_zero(num_request_queues, nr_cpu_ids), min_not_zero(num_request_queues, nr_cpu_ids),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment