cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
958e1b
From 89ada787b7d4c950c8bf95932c8c420d90c31c3c Mon Sep 17 00:00:00 2001
eb5a2f
From: Michael S. Tsirkin <mst@redhat.com>
958e1b
Date: Wed, 14 May 2014 08:33:08 +0200
958e1b
Subject: [PATCH 16/31] virtio: validate num_sg when mapping
eb5a2f
eb5a2f
RH-Author: Michael S. Tsirkin <mst@redhat.com>
958e1b
Message-id: <1400056377-6802-1-git-send-email-mst@redhat.com>
958e1b
Patchwork-id: 58862
958e1b
O-Subject: [PATCH qemu-kvm RHEL7.1 1/2] virtio: validate num_sg when mapping
958e1b
Bugzilla: 1095766
eb5a2f
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
eb5a2f
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
eb5a2f
RH-Acked-by: Amos Kong <akong@redhat.com>
eb5a2f
eb5a2f
CVE-2013-4535
eb5a2f
CVE-2013-4536
eb5a2f
eb5a2f
Both virtio-block and virtio-serial read,
eb5a2f
VirtQueueElements are read in as buffers, and passed to
eb5a2f
virtqueue_map_sg(), where num_sg is taken from the wire and can force
eb5a2f
writes to indicies beyond VIRTQUEUE_MAX_SIZE.
eb5a2f
eb5a2f
To fix, validate num_sg.
eb5a2f
eb5a2f
Reported-by: Michael Roth <mdroth@linux.vnet.ibm.com>
eb5a2f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
Cc: Amit Shah <amit.shah@redhat.com>
eb5a2f
Signed-off-by: Juan Quintela <quintela@redhat.com>
eb5a2f
(cherry picked from commit 36cf2a37132c7f01fa9adb5f95f5312b27742fd4)
eb5a2f
eb5a2f
Tested: lightly on developer's box
958e1b
Brew build: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=7452039
958e1b
Bugzilla:1095766
eb5a2f
---
eb5a2f
 hw/virtio/virtio.c | 6 ++++++
eb5a2f
 1 file changed, 6 insertions(+)
eb5a2f
eb5a2f
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
eb5a2f
---
eb5a2f
 hw/virtio/virtio.c |    6 ++++++
eb5a2f
 1 files changed, 6 insertions(+), 0 deletions(-)
eb5a2f
eb5a2f
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
eb5a2f
index 686dfbb..2667390 100644
eb5a2f
--- a/hw/virtio/virtio.c
eb5a2f
+++ b/hw/virtio/virtio.c
eb5a2f
@@ -423,6 +423,12 @@ void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,
eb5a2f
     unsigned int i;
eb5a2f
     hwaddr len;
eb5a2f
 
eb5a2f
+    if (num_sg >= VIRTQUEUE_MAX_SIZE) {
eb5a2f
+        error_report("virtio: map attempt out of bounds: %zd > %d",
eb5a2f
+                     num_sg, VIRTQUEUE_MAX_SIZE);
eb5a2f
+        exit(1);
eb5a2f
+    }
eb5a2f
+
eb5a2f
     for (i = 0; i < num_sg; i++) {
eb5a2f
         len = sg[i].iov_len;
eb5a2f
         sg[i].iov_base = cpu_physical_memory_map(addr[i], &len, is_write);
eb5a2f
-- 
eb5a2f
1.7.1
eb5a2f