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

958e1b
From 33ea847dbe677a3df68fecac80636050f72286ae Mon Sep 17 00:00:00 2001
eb5a2f
From: Michael S. Tsirkin <mst@redhat.com>
958e1b
Date: Wed, 14 May 2014 08:31:42 +0200
958e1b
Subject: [PATCH 11/31] virtio-net: out-of-bounds buffer write on load
eb5a2f
eb5a2f
RH-Author: Michael S. Tsirkin <mst@redhat.com>
958e1b
Message-id: <1400056285-6688-2-git-send-email-mst@redhat.com>
958e1b
Patchwork-id: 58856
958e1b
O-Subject: [PATCH qemu-kvm RHEL7.1] virtio-net: out-of-bounds buffer write on load
958e1b
Bugzilla: 1095685
eb5a2f
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
eb5a2f
RH-Acked-by: Juan Quintela <quintela@redhat.com>
958e1b
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
958e1b
RH-Acked-by: Amos Kong <akong@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
958e1b
Bugzilla: 1095685
eb5a2f
Tested: lightly on developer's box
958e1b
Brew build: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=7452039
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
958e1b
index 007cc2a..f72be9f 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