render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From e75abae126f9fcaf1e8478f0780ecae736f7d3e1 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <e75abae126f9fcaf1e8478f0780ecae736f7d3e1@dist-git>
c480ed
From: "Allen, John" <John.Allen@amd.com>
c480ed
Date: Tue, 2 Jul 2019 17:05:34 +0200
c480ed
Subject: [PATCH] Handle copying bitmaps to larger data buffers
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
If a bitmap of a shorter length than the data buffer is passed to
c480ed
virBitmapToDataBuf, it will read off the end of the bitmap and copy junk
c480ed
into the returned buffer. Add a check to only copy the length of the
c480ed
bitmap to the buffer.
c480ed
c480ed
The problem can be observed after setting a vcpu affinity using the vcpupin
c480ed
command on a system with a large number of cores:
c480ed
  # virsh vcpupin example_domain 0 0
c480ed
  # virsh vcpupin example_domain 0
c480ed
     VCPU   CPU Affinity
c480ed
    ---------------------------
c480ed
     0      0,192,197-198,202
c480ed
c480ed
Signed-off-by: John Allen <john.allen@amd.com>
c480ed
(cherry picked from commit 51f9f80d350e633adf479c6a9b3c55f82ca9cbd4)
c480ed
c480ed
https: //bugzilla.redhat.com/show_bug.cgi?id=1703160
c480ed
Signed-off-by: Erik Skultety <eskultet@redhat.com>
c480ed
Message-Id: <1a487c4f1ba9725eb7325debeeff2861d7047890.1562079635.git.eskultet@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/virbitmap.c | 4 ++++
c480ed
 1 file changed, 4 insertions(+)
c480ed
c480ed
diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
c480ed
index 49e542a4e6..7df0a2d4f3 100644
c480ed
--- a/src/util/virbitmap.c
c480ed
+++ b/src/util/virbitmap.c
c480ed
@@ -831,11 +831,15 @@ virBitmapToDataBuf(virBitmapPtr bitmap,
c480ed
                    unsigned char *bytes,
c480ed
                    size_t len)
c480ed
 {
c480ed
+    size_t nbytes = bitmap->map_len * (VIR_BITMAP_BITS_PER_UNIT / CHAR_BIT);
c480ed
     unsigned long *l;
c480ed
     size_t i, j;
c480ed
 
c480ed
     memset(bytes, 0, len);
c480ed
 
c480ed
+    /* If bitmap and buffer differ in size, only fill to the smaller length */
c480ed
+    len = MIN(len, nbytes);
c480ed
+
c480ed
     /* htole64 is not provided by gnulib, so we do the conversion by hand */
c480ed
     l = bitmap->map;
c480ed
     for (i = j = 0; i < len; i++, j++) {
c480ed
-- 
c480ed
2.22.0
c480ed