Blame 0013-virtio-validate-num_sg-when-mapping.patch

70114f
From f1344659fd93ea0dfb9d8d1af25993e57584c773 Mon Sep 17 00:00:00 2001
70114f
From: "Michael S. Tsirkin" <mst@redhat.com>
70114f
Date: Thu, 3 Apr 2014 19:51:53 +0300
70114f
Subject: [PATCH] virtio: validate num_sg when mapping
70114f
70114f
CVE-2013-4535
70114f
CVE-2013-4536
70114f
70114f
Both virtio-block and virtio-serial read,
70114f
VirtQueueElements are read in as buffers, and passed to
70114f
virtqueue_map_sg(), where num_sg is taken from the wire and can force
70114f
writes to indicies beyond VIRTQUEUE_MAX_SIZE.
70114f
70114f
To fix, validate num_sg.
70114f
70114f
Reported-by: Michael Roth <mdroth@linux.vnet.ibm.com>
70114f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
70114f
Cc: Amit Shah <amit.shah@redhat.com>
70114f
Signed-off-by: Juan Quintela <quintela@redhat.com>
70114f
(cherry picked from commit 36cf2a37132c7f01fa9adb5f95f5312b27742fd4)
70114f
---
70114f
 hw/virtio/virtio.c | 6 ++++++
70114f
 1 file changed, 6 insertions(+)
70114f
70114f
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
70114f
index 0072542..a70169a 100644
70114f
--- a/hw/virtio/virtio.c
70114f
+++ b/hw/virtio/virtio.c
70114f
@@ -430,6 +430,12 @@ void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
70114f
     unsigned int i;
70114f
     hwaddr len;
70114f
 
70114f
+    if (num_sg >= VIRTQUEUE_MAX_SIZE) {
70114f
+        error_report("virtio: map attempt out of bounds: %zd > %d",
70114f
+                     num_sg, VIRTQUEUE_MAX_SIZE);
70114f
+        exit(1);
70114f
+    }
70114f
+
70114f
     for (i = 0; i < num_sg; i++) {
70114f
         len = sg[i].iov_len;
70114f
         sg[i].iov_base = cpu_physical_memory_map(addr[i], &len, is_write);