yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-virtio-net-out-of-bounds-buffer-write-on-load.patch

eb5a2f
From a3f3310a41ed5af1c701fea5dd7892dd9409e7d8 Mon Sep 17 00:00:00 2001
eb5a2f
From: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
Date: Wed, 14 May 2014 08:07:42 +0200
eb5a2f
Subject: [PATCH 02/30] virtio-net: out-of-bounds buffer write on load
eb5a2f
eb5a2f
RH-Author: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
Message-id: <1400054498-4366-2-git-send-email-mst@redhat.com>
eb5a2f
Patchwork-id: 58840
eb5a2f
O-Subject: [PATCH qemu-kvm RHEL7.0] virtio-net: out-of-bounds buffer write on load
eb5a2f
Bugzilla: 1095684
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: Juan Quintela <quintela@redhat.com>
eb5a2f
eb5a2f
CVE-2013-4149 QEMU 1.3.0 out-of-bounds buffer write in
eb5a2f
virtio_net_load()@hw/net/virtio-net.c
eb5a2f
eb5a2f
>         } else if (n->mac_table.in_use) {
eb5a2f
>             uint8_t *buf = g_malloc0(n->mac_table.in_use);
eb5a2f
eb5a2f
We are allocating buffer of size n->mac_table.in_use
eb5a2f
eb5a2f
>             qemu_get_buffer(f, buf, n->mac_table.in_use * ETH_ALEN);
eb5a2f
eb5a2f
and read to the n->mac_table.in_use size buffer n->mac_table.in_use *
eb5a2f
ETH_ALEN bytes, corrupting memory.
eb5a2f
eb5a2f
If adversary controls state then memory written there is controlled
eb5a2f
by adversary.
eb5a2f
eb5a2f
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
eb5a2f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
Signed-off-by: Juan Quintela <quintela@redhat.com>
eb5a2f
(cherry picked from commit 98f93ddd84800f207889491e0b5d851386b459cf)
eb5a2f
eb5a2f
Bugzilla: 1095684
eb5a2f
Tested: lightly on developer's box
eb5a2f
Brew build: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=7450401
eb5a2f
---
eb5a2f
 hw/net/virtio-net.c | 15 +++++++++++----
eb5a2f
 1 file changed, 11 insertions(+), 4 deletions(-)
eb5a2f
eb5a2f
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
eb5a2f
---
eb5a2f
 hw/net/virtio-net.c |   15 +++++++++++----
eb5a2f
 1 files changed, 11 insertions(+), 4 deletions(-)
eb5a2f
eb5a2f
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
eb5a2f
index 2d559e0..f6ed241 100644
eb5a2f
--- a/hw/net/virtio-net.c
eb5a2f
+++ b/hw/net/virtio-net.c
eb5a2f
@@ -1273,10 +1273,17 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
eb5a2f
         if (n->mac_table.in_use <= MAC_TABLE_ENTRIES) {
eb5a2f
             qemu_get_buffer(f, n->mac_table.macs,
eb5a2f
                             n->mac_table.in_use * ETH_ALEN);
eb5a2f
-        } else if (n->mac_table.in_use) {
eb5a2f
-            uint8_t *buf = g_malloc0(n->mac_table.in_use);
eb5a2f
-            qemu_get_buffer(f, buf, n->mac_table.in_use * ETH_ALEN);
eb5a2f
-            g_free(buf);
eb5a2f
+        } else {
eb5a2f
+            int64_t i;
eb5a2f
+
eb5a2f
+            /* Overflow detected - can happen if source has a larger MAC table.
eb5a2f
+             * We simply set overflow flag so there's no need to maintain the
eb5a2f
+             * table of addresses, discard them all.
eb5a2f
+             * Note: 64 bit math to avoid integer overflow.
eb5a2f
+             */
eb5a2f
+            for (i = 0; i < (int64_t)n->mac_table.in_use * ETH_ALEN; ++i) {
eb5a2f
+                qemu_get_byte(f);
eb5a2f
+            }
eb5a2f
             n->mac_table.multi_overflow = n->mac_table.uni_overflow = 1;
eb5a2f
             n->mac_table.in_use = 0;
eb5a2f
         }
eb5a2f
-- 
eb5a2f
1.7.1
eb5a2f