render / rpms / libvirt

Forked from rpms/libvirt 4 months ago
Clone
99cbc7
From 806c01fea005e3887ad74efa3ecbab8294c0ddca Mon Sep 17 00:00:00 2001
99cbc7
Message-Id: <806c01fea005e3887ad74efa3ecbab8294c0ddca@dist-git>
99cbc7
From: "Allen, John" <John.Allen@amd.com>
99cbc7
Date: Fri, 26 Apr 2019 15:12:01 +0200
99cbc7
Subject: [PATCH] Handle copying bitmaps to larger data buffers
99cbc7
99cbc7
If a bitmap of a shorter length than the data buffer is passed to
99cbc7
virBitmapToDataBuf, it will read off the end of the bitmap and copy junk
99cbc7
into the returned buffer. Add a check to only copy the length of the
99cbc7
bitmap to the buffer.
99cbc7
99cbc7
The problem can be observed after setting a vcpu affinity using the vcpupin
99cbc7
command on a system with a large number of cores:
99cbc7
  # virsh vcpupin example_domain 0 0
99cbc7
  # virsh vcpupin example_domain 0
99cbc7
     VCPU   CPU Affinity
99cbc7
    ---------------------------
99cbc7
     0      0,192,197-198,202
99cbc7
99cbc7
Signed-off-by: John Allen <john.allen@amd.com>
99cbc7
(cherry picked from commit 51f9f80d350e633adf479c6a9b3c55f82ca9cbd4)
99cbc7
99cbc7
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1703159
99cbc7
99cbc7
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
99cbc7
Message-Id: <8c72d73f39288e0a38d72481e771d1df53d593a3.1556284274.git.phrdina@redhat.com>
99cbc7
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
99cbc7
---
99cbc7
 src/util/virbitmap.c | 4 ++++
99cbc7
 1 file changed, 4 insertions(+)
99cbc7
99cbc7
diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
99cbc7
index 0cc5292d8c..0bc0d068bb 100644
99cbc7
--- a/src/util/virbitmap.c
99cbc7
+++ b/src/util/virbitmap.c
99cbc7
@@ -832,11 +832,15 @@ virBitmapToDataBuf(virBitmapPtr bitmap,
99cbc7
                    unsigned char *bytes,
99cbc7
                    size_t len)
99cbc7
 {
99cbc7
+    size_t nbytes = bitmap->map_len * (VIR_BITMAP_BITS_PER_UNIT / CHAR_BIT);
99cbc7
     unsigned long *l;
99cbc7
     size_t i, j;
99cbc7
 
99cbc7
     memset(bytes, 0, len);
99cbc7
 
99cbc7
+    /* If bitmap and buffer differ in size, only fill to the smaller length */
99cbc7
+    len = MIN(len, nbytes);
99cbc7
+
99cbc7
     /* htole64 is not provided by gnulib, so we do the conversion by hand */
99cbc7
     l = bitmap->map;
99cbc7
     for (i = j = 0; i < len; i++, j++) {
99cbc7
-- 
99cbc7
2.21.0
99cbc7