]> xenbits.xensource.com Git - qemu-upstream-4.2-testing.git/commitdiff
virtio: validate num_sg when mapping
authorMichael S. Tsirkin <mst@redhat.com>
Wed, 4 Mar 2015 16:44:22 +0000 (16:44 +0000)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Thu, 5 Mar 2015 13:22:11 +0000 (13:22 +0000)
CVE-2013-4535
CVE-2013-4536

Both virtio-block and virtio-serial read,
VirtQueueElements are read in as buffers, and passed to
virtqueue_map_sg(), where num_sg is taken from the wire and can force
writes to indicies beyond VIRTQUEUE_MAX_SIZE.

To fix, validate num_sg.

Reported-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Cc: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
hw/virtio.c

index e1365a3f78be521f2ec12df7f3ffaee662fee2e0..068c24dc1936f0a1cb6e2b1d25e18e20d33a2960 100644 (file)
@@ -396,6 +396,12 @@ void virtqueue_map_sg(struct iovec *sg, target_phys_addr_t *addr,
     unsigned int i;
     target_phys_addr_t len;
 
+    if (num_sg >= VIRTQUEUE_MAX_SIZE) {
+        error_report("virtio: map attempt out of bounds: %zd > %d",
+                     num_sg, VIRTQUEUE_MAX_SIZE);
+        exit(1);
+    }
+
     for (i = 0; i < num_sg; i++) {
         len = sg[i].iov_len;
         sg[i].iov_base = cpu_physical_memory_map(addr[i], &len, is_write);