From f3c2a669593d5f4bfa7aa002ccbbaaca013f8e2f Mon Sep 17 00:00:00 2001 From: Nelson Elhage <<nelhage@ksplice.com>> Date: Thu, 19 May 2011 13:23:17 -0400 Subject: virtqueue: Sanity-check the length of indirect descriptors. We were previously allowing arbitrarily-long descriptors, which could lead to a buffer overflow in the qemu-kvm process. --- hw/virtio.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/virtio.c b/hw/virtio.c index 31bd9e32d..1ad857336 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -336,6 +336,11 @@ int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes) max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc); num_bufs = i = 0; desc_pa = vring_desc_addr(desc_pa, i); + + if (max > VIRTQUEUE_MAX_SIZE) { + error_report("Too-large indirect descriptor"); + exit(1); + } } do { @@ -406,6 +411,11 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem) max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc); desc_pa = vring_desc_addr(desc_pa, i); i = 0; + + if (max > VIRTQUEUE_MAX_SIZE) { + error_report("Too-large indirect descriptor"); + exit(1); + } } /* Collect all the descriptors */ -- cgit v1.2.3-65-gdbad