render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
bcddb9
From b470757774a776e2bcbff50c7ae7f40323d10064 Mon Sep 17 00:00:00 2001
bcddb9
Message-Id: <b470757774a776e2bcbff50c7ae7f40323d10064@dist-git>
bcddb9
From: Michal Privoznik <mprivozn@redhat.com>
bcddb9
Date: Thu, 7 Mar 2019 14:17:01 +0100
bcddb9
Subject: [PATCH] cpu: Don't access invalid memory in virCPUx86Translate
bcddb9
MIME-Version: 1.0
bcddb9
Content-Type: text/plain; charset=UTF-8
bcddb9
Content-Transfer-Encoding: 8bit
bcddb9
bcddb9
Problem is that if there are no signatures for a CPU, then we
bcddb9
still allocate cpu->signatures (even though with size 0). Later,
bcddb9
we access cpu->signatures[0] if cpu->signatures is not NULL.
bcddb9
bcddb9
 Invalid read of size 4
bcddb9
    at 0x5F439D7: virCPUx86Translate (cpu_x86.c:2930)
bcddb9
    by 0x5F3C239: virCPUTranslate (cpu.c:927)
bcddb9
    by 0x57CE7A1: qemuProcessUpdateGuestCPU (qemu_process.c:5870)
bcddb9
    ...
bcddb9
  Address 0xf752d40 is 0 bytes after a block of size 0 alloc'd
bcddb9
    at 0x4C30EC6: calloc (vg_replace_malloc.c:711)
bcddb9
    by 0x5DBDE4E: virAllocN (viralloc.c:190)
bcddb9
    by 0x5F3E4FA: x86ModelCopySignatures (cpu_x86.c:990)
bcddb9
    by 0x5F3E60F: x86ModelCopy (cpu_x86.c:1008)
bcddb9
    by 0x5F3E7CB: x86ModelFromCPU (cpu_x86.c:1068)
bcddb9
    by 0x5F4397E: virCPUx86Translate (cpu_x86.c:2922)
bcddb9
    by 0x5F3C239: virCPUTranslate (cpu.c:927)
bcddb9
    by 0x57CE7A1: qemuProcessUpdateGuestCPU (qemu_process.c:5870)
bcddb9
    ...
bcddb9
bcddb9
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
bcddb9
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
bcddb9
(cherry picked from commit 62cb9c335c43a722e81ac0a1ed6e1111ba1d428b)
bcddb9
bcddb9
https://bugzilla.redhat.com/show_bug.cgi?id=1558558
bcddb9
https://bugzilla.redhat.com/show_bug.cgi?id=1687515
bcddb9
bcddb9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
bcddb9
Reviewed-by: Ján Tomko <jtomko@redhat.com>
bcddb9
---
bcddb9
 src/cpu/cpu_x86.c | 3 +++
bcddb9
 1 file changed, 3 insertions(+)
bcddb9
bcddb9
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
bcddb9
index f6844aaa0d..466c79031d 100644
bcddb9
--- a/src/cpu/cpu_x86.c
bcddb9
+++ b/src/cpu/cpu_x86.c
bcddb9
@@ -1021,6 +1021,9 @@ x86ModelCopySignatures(virCPUx86ModelPtr dst,
bcddb9
 {
bcddb9
     size_t i;
bcddb9
 
bcddb9
+    if (src->nsignatures == 0)
bcddb9
+        return 0;
bcddb9
+
bcddb9
     if (VIR_ALLOC_N(dst->signatures, src->nsignatures) < 0)
bcddb9
         return -1;
bcddb9
 
bcddb9
-- 
bcddb9
2.21.0
bcddb9