diff mbox series

vhost-user-blk: Fail gracefully on too large queue size

Message ID 20210413165240.43386-1-kwolf@redhat.com (mailing list archive)
State New, archived
Headers show
Series vhost-user-blk: Fail gracefully on too large queue size | expand

Commit Message

Kevin Wolf April 13, 2021, 4:52 p.m. UTC
virtio_add_queue() aborts when queue_size > VIRTQUEUE_MAX_SIZE, so
vhost_user_blk_device_realize() should check this before calling it.

Simple reproducer:

qemu-system-x86_64 \
    -chardev null,id=foo \
    -device vhost-user-blk-pci,queue-size=4096,chardev=foo

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1935014
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 hw/block/vhost-user-blk.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Kevin Wolf April 13, 2021, 4:59 p.m. UTC | #1
Am 13.04.2021 um 18:52 hat Kevin Wolf geschrieben:
> virtio_add_queue() aborts when queue_size > VIRTQUEUE_MAX_SIZE, so
> vhost_user_blk_device_realize() should check this before calling it.
> 
> Simple reproducer:
> 
> qemu-system-x86_64 \
>     -chardev null,id=foo \
>     -device vhost-user-blk-pci,queue-size=4096,chardev=foo
> 
> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1935014
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  hw/block/vhost-user-blk.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
> index 0b5b9d44cd..531e4ea063 100644
> --- a/hw/block/vhost-user-blk.c
> +++ b/hw/block/vhost-user-blk.c
> @@ -467,6 +467,11 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
>          error_setg(errp, "vhost-user-blk: queue size must be non-zero");
>          return;
>      }
> +    if (s->queue_size) {

Sorry, obviously I didn't send the right one... Please look at v2 where
this actually checks what the commit message promises.

Kevin

> +        error_setg(errp, "vhost-user-blk: queue size must not exceed %d",
> +                   VIRTQUEUE_MAX_SIZE);
> +        return;
> +    }
>  
>      if (!vhost_user_init(&s->vhost_user, &s->chardev, errp)) {
>          return;
> -- 
> 2.30.2
>
diff mbox series

Patch

diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index 0b5b9d44cd..531e4ea063 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -467,6 +467,11 @@  static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
         error_setg(errp, "vhost-user-blk: queue size must be non-zero");
         return;
     }
+    if (s->queue_size) {
+        error_setg(errp, "vhost-user-blk: queue size must not exceed %d",
+                   VIRTQUEUE_MAX_SIZE);
+        return;
+    }
 
     if (!vhost_user_init(&s->vhost_user, &s->chardev, errp)) {
         return;