Skip to contentSkip to conversation

virtio: check vring descriptor buffer length

PATCH In review P J P 4 participants 4 messages Jul 27, 2016 – Jul 28, 2016

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH 1/1 virtio: check vring descriptor buffer length

From: Prasad J Pandit <[email protected]>

virtio back end uses set of buffers to facilitate I/O operations. An infinite loop unfolds in virtqueue_pop() if a buffer was of zero size. Add check to avoid it.

---
 hw/virtio/virtio.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/virtio/virtio.c +5 -0
index 30ede3d..8de896c 100644
@@ -457,6 +457,11 @@ static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove
     unsigned num_sg = *p_num_sg;
     assert(num_sg <= max_num_sg);
 
+    if (!sz) {
+        error_report("virtio: zero sized buffers are not allowed");
+        exit(1);
+    }
+
     while (sz) {
         hwaddr len = sz;
 
Signature · 1 line
2.5.5
#1 lore raw
Quoted 17 lines · P J P

From: Prasad J Pandit <[email protected]>

virtio back end uses set of buffers to facilitate I/O operations. An infinite loop unfolds in virtqueue_pop() if a buffer was of zero size. Add check to avoid it.

---
 hw/virtio/virtio.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/virtio/virtio.c +0 -0
index 30ede3d..8de896c 100644

hw/virtio/virtio.c static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove · line 463

Quoted 7 lines
hw/virtio/virtio.c +4 -0
@@ -457,6 +457,11 @@ static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove
     unsigned num_sg = *p_num_sg;
     assert(num_sg <= max_num_sg);
 
+    if (!sz) {
+        error_report("virtio: zero sized buffers are not allowed");
+        exit(1);
+    }

This lets the guest forcefully exit qemu. Isn't it better to just make the guest error degrade the virtio device into a broken state (the guest can no longer use it, but qemu doesn't exit)?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 21 lines · Eric Blake
Quoted 20 lines · P J P

From: Prasad J Pandit <[email protected]>

virtio back end uses set of buffers to facilitate I/O operations. An infinite loop unfolds in virtqueue_pop() if a buffer was of zero size. Add check to avoid it.

---
 hw/virtio/virtio.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/virtio/virtio.c +0 -0
index 30ede3d..8de896c 100644
@@ -457,6 +457,11 @@ static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove
     unsigned num_sg = *p_num_sg;
     assert(num_sg <= max_num_sg);
 
Quoted 13 lines

hw/virtio/virtio.c static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iove · line 463

Quoted 4 lines
hw/virtio/virtio.c +4 -0
+    if (!sz) {
+        error_report("virtio: zero sized buffers are not allowed");
+        exit(1);
+    }

This lets the guest forcefully exit qemu. Isn't it better to just make the guest error degrade the virtio device into a broken state (the guest can no longer use it, but qemu doesn't exit)?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

ATM that's how other guest bugs are handled so I think it's fine. With a kernel driver it's easy for guest to forcefully exit qemu anyway. Hey just call halt().
We do want to improve this over time, and in particular supporting dpdk within guest will need that, but I don't think we should block this fix because of that.

Signature · 1 line
MST
Reviewed-by on v1 1/1
#3 lore raw
In reply to P J P
Quoted 11 lines · P J P

From: Prasad J Pandit <[email protected]>

virtio back end uses set of buffers to facilitate I/O operations. An infinite loop unfolds in virtqueue_pop() if a buffer was of zero size. Add check to avoid it.

---
 hw/virtio/virtio.c | 5 +++++
 1 file changed, 5 insertions(+)