Update qemu package to mitigate CVE-2015-3456
[packages/centos6/qemu.git] / 0023-virtio-net-out-of-bounds-buffer-write-on-load.patch
1 From 1a29e58f9f23846d0e105a3157629786fc624f65 Mon Sep 17 00:00:00 2001
2 From: "Michael S. Tsirkin" <mst@redhat.com>
3 Date: Mon, 28 Apr 2014 16:08:21 +0300
4 Subject: [PATCH] virtio-net: out-of-bounds buffer write on load
5
6 CVE-2013-4149 QEMU 1.3.0 out-of-bounds buffer write in
7 virtio_net_load()@hw/net/virtio-net.c
8
9 >         } else if (n->mac_table.in_use) {
10 >             uint8_t *buf = g_malloc0(n->mac_table.in_use);
11
12 We are allocating buffer of size n->mac_table.in_use
13
14 >             qemu_get_buffer(f, buf, n->mac_table.in_use * ETH_ALEN);
15
16 and read to the n->mac_table.in_use size buffer n->mac_table.in_use *
17 ETH_ALEN bytes, corrupting memory.
18
19 If adversary controls state then memory written there is controlled
20 by adversary.
21
22 Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
23 Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
24 Signed-off-by: Juan Quintela <quintela@redhat.com>
25 (cherry picked from commit 98f93ddd84800f207889491e0b5d851386b459cf)
26 ---
27  hw/net/virtio-net.c | 15 +++++++++++----
28  1 file changed, 11 insertions(+), 4 deletions(-)
29
30 diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
31 index 0a8cb40..940a7cf 100644
32 --- a/hw/net/virtio-net.c
33 +++ b/hw/net/virtio-net.c
34 @@ -1362,10 +1362,17 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
35          if (n->mac_table.in_use <= MAC_TABLE_ENTRIES) {
36              qemu_get_buffer(f, n->mac_table.macs,
37                              n->mac_table.in_use * ETH_ALEN);
38 -        } else if (n->mac_table.in_use) {
39 -            uint8_t *buf = g_malloc0(n->mac_table.in_use);
40 -            qemu_get_buffer(f, buf, n->mac_table.in_use * ETH_ALEN);
41 -            g_free(buf);
42 +        } else {
43 +            int64_t i;
44 +
45 +            /* Overflow detected - can happen if source has a larger MAC table.
46 +             * We simply set overflow flag so there's no need to maintain the
47 +             * table of addresses, discard them all.
48 +             * Note: 64 bit math to avoid integer overflow.
49 +             */
50 +            for (i = 0; i < (int64_t)n->mac_table.in_use * ETH_ALEN; ++i) {
51 +                qemu_get_byte(f);
52 +            }
53              n->mac_table.multi_overflow = n->mac_table.uni_overflow = 1;
54              n->mac_table.in_use = 0;
55          }