thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 8 months ago
Clone
29b115
From 4dad0e9abbc843fba4e5fee6e7aa1b0db13f5898 Mon Sep 17 00:00:00 2001
29b115
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
29b115
Date: Thu, 21 Jul 2022 15:27:35 +0200
29b115
Subject: [PATCH 03/32] hw/virtio: Replace g_memdup() by g_memdup2()
29b115
MIME-Version: 1.0
29b115
Content-Type: text/plain; charset=UTF-8
29b115
Content-Transfer-Encoding: 8bit
29b115
29b115
RH-Author: Eugenio Pérez <eperezma@redhat.com>
29b115
RH-MergeRequest: 108: Net Control Virtqueue shadow Support
29b115
RH-Commit: [3/27] ae196903eb1a7aebbf999100e997cf82e5024cb6 (eperezmartin/qemu-kvm)
29b115
RH-Bugzilla: 1939363
29b115
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
29b115
RH-Acked-by: Cindy Lu <lulu@redhat.com>
29b115
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
29b115
29b115
Bugzilla: https://bugzilla.redhat.com/1939363
29b115
29b115
Upstream Status: git://git.qemu.org/qemu.git
29b115
29b115
commit d792199de55ca5cb5334016884039c740290b5c7
29b115
Author: Philippe Mathieu-Daudé <f4bug@amsat.org>
29b115
Date:   Thu May 12 19:57:46 2022 +0200
29b115
29b115
    hw/virtio: Replace g_memdup() by g_memdup2()
29b115
29b115
    Per https://discourse.gnome.org/t/port-your-module-from-g-memdup-to-g-memdup2-now/5538
29b115
29b115
      The old API took the size of the memory to duplicate as a guint,
29b115
      whereas most memory functions take memory sizes as a gsize. This
29b115
      made it easy to accidentally pass a gsize to g_memdup(). For large
29b115
      values, that would lead to a silent truncation of the size from 64
29b115
      to 32 bits, and result in a heap area being returned which is
29b115
      significantly smaller than what the caller expects. This can likely
29b115
      be exploited in various modules to cause a heap buffer overflow.
29b115
29b115
    Replace g_memdup() by the safer g_memdup2() wrapper.
29b115
29b115
    Acked-by: Jason Wang <jasowang@redhat.com>
29b115
    Acked-by: Eugenio Pérez <eperezma@redhat.com>
29b115
    Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
29b115
    Message-Id: <20220512175747.142058-6-eperezma@redhat.com>
29b115
    Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
29b115
    Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
29b115
29b115
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
29b115
---
29b115
 hw/net/virtio-net.c       | 3 ++-
29b115
 hw/virtio/virtio-crypto.c | 6 +++---
29b115
 2 files changed, 5 insertions(+), 4 deletions(-)
29b115
29b115
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
29b115
index 099e65036d..633de61513 100644
29b115
--- a/hw/net/virtio-net.c
29b115
+++ b/hw/net/virtio-net.c
29b115
@@ -1458,7 +1458,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
29b115
         }
29b115
 
29b115
         iov_cnt = elem->out_num;
29b115
-        iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) * elem->out_num);
29b115
+        iov2 = iov = g_memdup2(elem->out_sg,
29b115
+                               sizeof(struct iovec) * elem->out_num);
29b115
         s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl));
29b115
         iov_discard_front(&iov, &iov_cnt, sizeof(ctrl));
29b115
         if (s != sizeof(ctrl)) {
29b115
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
29b115
index dcd80b904d..0e31e3cc04 100644
29b115
--- a/hw/virtio/virtio-crypto.c
29b115
+++ b/hw/virtio/virtio-crypto.c
29b115
@@ -242,7 +242,7 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
29b115
         }
29b115
 
29b115
         out_num = elem->out_num;
29b115
-        out_iov_copy = g_memdup(elem->out_sg, sizeof(out_iov[0]) * out_num);
29b115
+        out_iov_copy = g_memdup2(elem->out_sg, sizeof(out_iov[0]) * out_num);
29b115
         out_iov = out_iov_copy;
29b115
 
29b115
         in_num = elem->in_num;
29b115
@@ -605,11 +605,11 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request)
29b115
     }
29b115
 
29b115
     out_num = elem->out_num;
29b115
-    out_iov_copy = g_memdup(elem->out_sg, sizeof(out_iov[0]) * out_num);
29b115
+    out_iov_copy = g_memdup2(elem->out_sg, sizeof(out_iov[0]) * out_num);
29b115
     out_iov = out_iov_copy;
29b115
 
29b115
     in_num = elem->in_num;
29b115
-    in_iov_copy = g_memdup(elem->in_sg, sizeof(in_iov[0]) * in_num);
29b115
+    in_iov_copy = g_memdup2(elem->in_sg, sizeof(in_iov[0]) * in_num);
29b115
     in_iov = in_iov_copy;
29b115
 
29b115
     if (unlikely(iov_to_buf(out_iov, out_num, 0, &req, sizeof(req))
29b115
-- 
29b115
2.31.1
29b115