Skip to contentSkip to conversation

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

PATCH Superseded Kevin Wolf 1 participant 2 messages Apr 13, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

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

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
---
 hw/block/vhost-user-blk.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/block/vhost-user-blk.c +5 -0
index 0b5b9d44cd..531e4ea063 100644
@@ -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;
Signature · 1 line
2.30.2
author
#1 lore raw

Am 13.04.2021 um 18:52 hat Kevin Wolf geschrieben:

Quoted 20 lines

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
---
 hw/block/vhost-user-blk.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/block/vhost-user-blk.c +0 -0
index 0b5b9d44cd..531e4ea063 100644

hw/block/vhost-user-blk.c static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) · line 470

Quoted 4 lines
hw/block/vhost-user-blk.c +1 -0
@@ -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

Quoted 10 lines
hw/block/vhost-user-blk.c +4 -0
+        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;
Signature · 1 line
2.30.2