dcavalca / rpms / qemu

Forked from rpms/qemu 11 months ago
Clone

Blame 0004-virtio-net-fix-buffer-overflow-on-invalid-state-load.patch

70114f
From ea96c6a9c91da1923aa922a781fd7abbf9f51b6c Mon Sep 17 00:00:00 2001
70114f
From: "Michael S. Tsirkin" <mst@redhat.com>
70114f
Date: Thu, 3 Apr 2014 19:50:39 +0300
70114f
Subject: [PATCH] virtio-net: fix buffer overflow on invalid state load
70114f
70114f
CVE-2013-4148 QEMU 1.0 integer conversion in
70114f
virtio_net_load()@hw/net/virtio-net.c
70114f
70114f
Deals with loading a corrupted savevm image.
70114f
70114f
>         n->mac_table.in_use = qemu_get_be32(f);
70114f
70114f
in_use is int so it can get negative when assigned 32bit unsigned value.
70114f
70114f
>         /* MAC_TABLE_ENTRIES may be different from the saved image */
70114f
>         if (n->mac_table.in_use <= MAC_TABLE_ENTRIES) {
70114f
70114f
passing this check ^^^
70114f
70114f
>             qemu_get_buffer(f, n->mac_table.macs,
70114f
>                             n->mac_table.in_use * ETH_ALEN);
70114f
70114f
with good in_use value, "n->mac_table.in_use * ETH_ALEN" can get
70114f
positive and bigger than mac_table.macs. For example 0x81000000
70114f
satisfies this condition when ETH_ALEN is 6.
70114f
70114f
Fix it by making the value unsigned.
70114f
For consistency, change first_multi as well.
70114f
70114f
Note: all call sites were audited to confirm that
70114f
making them unsigned didn't cause any issues:
70114f
it turns out we actually never do math on them,
70114f
so it's easy to validate because both values are
70114f
always <= MAC_TABLE_ENTRIES.
70114f
70114f
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
70114f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
70114f
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
70114f
Signed-off-by: Juan Quintela <quintela@redhat.com>
70114f
(cherry picked from commit 71f7fe48e10a8437c9d42d859389f37157f59980)
70114f
---
70114f
 include/hw/virtio/virtio-net.h | 4 ++--
70114f
 1 file changed, 2 insertions(+), 2 deletions(-)
70114f
70114f
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
70114f
index df60f16..4b32440 100644
70114f
--- a/include/hw/virtio/virtio-net.h
70114f
+++ b/include/hw/virtio/virtio-net.h
70114f
@@ -176,8 +176,8 @@ typedef struct VirtIONet {
70114f
     uint8_t nobcast;
70114f
     uint8_t vhost_started;
70114f
     struct {
70114f
-        int in_use;
70114f
-        int first_multi;
70114f
+        uint32_t in_use;
70114f
+        uint32_t first_multi;
70114f
         uint8_t multi_overflow;
70114f
         uint8_t uni_overflow;
70114f
         uint8_t *macs;