yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
26ba25
From b373cd31bd40fff153ecbeb4695b8667db28e4e0 Mon Sep 17 00:00:00 2001
26ba25
From: Xiao Wang <jasowang@redhat.com>
26ba25
Date: Fri, 11 Jan 2019 07:58:57 +0000
26ba25
Subject: [PATCH 02/11] rtl8139: fix possible out of bound access
26ba25
MIME-Version: 1.0
26ba25
Content-Type: text/plain; charset=UTF-8
26ba25
Content-Transfer-Encoding: 8bit
26ba25
26ba25
RH-Author: Xiao Wang <jasowang@redhat.com>
26ba25
Message-id: <20190111075904.2030-3-jasowang@redhat.com>
26ba25
Patchwork-id: 83975
26ba25
O-Subject: [RHEL8 qemu-kvm PATCH 2/9] rtl8139: fix possible out of bound access
26ba25
Bugzilla: 1636784
26ba25
RH-Acked-by: Thomas Huth <thuth@redhat.com>
26ba25
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
26ba25
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
26ba25
RH-Acked-by: Maxime Coquelin <maxime.coquelin@redhat.com>
26ba25
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
26ba25
26ba25
In rtl8139_do_receive(), we try to assign size_ to size which converts
26ba25
from size_t to integer. This will cause troubles when size_ is greater
26ba25
INT_MAX, this will lead a negative value in size and it can then pass
26ba25
the check of size < MIN_BUF_SIZE which may lead out of bound access of
26ba25
for both buf and buf1.
26ba25
26ba25
Fixing by converting the type of size to size_t.
26ba25
26ba25
CC: qemu-stable@nongnu.org
26ba25
Reported-by: Daniel Shapira <daniel@twistlock.com>
26ba25
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
26ba25
Signed-off-by: Jason Wang <jasowang@redhat.com>
26ba25
(cherry picked from commit 1a326646fef38782e5542280040ec3ea23e4a730)
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 hw/net/rtl8139.c | 8 ++++----
26ba25
 1 file changed, 4 insertions(+), 4 deletions(-)
26ba25
26ba25
diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
26ba25
index 05453e7..0c916b7 100644
26ba25
--- a/hw/net/rtl8139.c
26ba25
+++ b/hw/net/rtl8139.c
26ba25
@@ -817,7 +817,7 @@ static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t
26ba25
     RTL8139State *s = qemu_get_nic_opaque(nc);
26ba25
     PCIDevice *d = PCI_DEVICE(s);
26ba25
     /* size is the length of the buffer passed to the driver */
26ba25
-    int size = size_;
26ba25
+    size_t size = size_;
26ba25
     const uint8_t *dot1q_buf = NULL;
26ba25
 
26ba25
     uint32_t packet_header = 0;
26ba25
@@ -826,7 +826,7 @@ static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t
26ba25
     static const uint8_t broadcast_macaddr[6] =
26ba25
         { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
26ba25
 
26ba25
-    DPRINTF(">>> received len=%d\n", size);
26ba25
+    DPRINTF(">>> received len=%zu\n", size);
26ba25
 
26ba25
     /* test if board clock is stopped */
26ba25
     if (!s->clock_enabled)
26ba25
@@ -1035,7 +1035,7 @@ static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t
26ba25
 
26ba25
         if (size+4 > rx_space)
26ba25
         {
26ba25
-            DPRINTF("C+ Rx mode : descriptor %d size %d received %d + 4\n",
26ba25
+            DPRINTF("C+ Rx mode : descriptor %d size %d received %zu + 4\n",
26ba25
                 descriptor, rx_space, size);
26ba25
 
26ba25
             s->IntrStatus |= RxOverflow;
26ba25
@@ -1148,7 +1148,7 @@ static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t
26ba25
         if (avail != 0 && RX_ALIGN(size + 8) >= avail)
26ba25
         {
26ba25
             DPRINTF("rx overflow: rx buffer length %d head 0x%04x "
26ba25
-                "read 0x%04x === available 0x%04x need 0x%04x\n",
26ba25
+                "read 0x%04x === available 0x%04x need 0x%04zx\n",
26ba25
                 s->RxBufferSize, s->RxBufAddr, s->RxBufPtr, avail, size + 8);
26ba25
 
26ba25
             s->IntrStatus |= RxOverflow;
26ba25
-- 
26ba25
1.8.3.1
26ba25