virtio: check vring descriptor buffer length
authorPrasad J Pandit <pjp@fedoraproject.org>
Wed, 27 Jul 2016 15:37:56 +0000 (21:07 +0530)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 28 Jul 2016 21:07:10 +0000 (00:07 +0300)
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.

Reported-by: Li Qiang <liqiang6-s@360.cn>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
hw/virtio/virtio.c

index 752b2715d0bec2f23b376756cd854ebcee6ba343..b4d05110d2730369a648194f4cc75002aeeb5010 100644 (file)
@@ -458,6 +458,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;