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