]> xenbits.xensource.com Git - libvirt.git/commitdiff
cpu: Don't access invalid memory in virCPUx86Translate
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 7 Mar 2019 13:17:01 +0000 (14:17 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 7 Mar 2019 14:30:40 +0000 (15:30 +0100)
Problem is that if there are no signatures for a CPU, then we
still allocate cpu->signatures (even though with size 0). Later,
we access cpu->signatures[0] if cpu->signatures is not NULL.

 Invalid read of size 4
    at 0x5F439D7: virCPUx86Translate (cpu_x86.c:2930)
    by 0x5F3C239: virCPUTranslate (cpu.c:927)
    by 0x57CE7A1: qemuProcessUpdateGuestCPU (qemu_process.c:5870)
    ...
  Address 0xf752d40 is 0 bytes after a block of size 0 alloc'd
    at 0x4C30EC6: calloc (vg_replace_malloc.c:711)
    by 0x5DBDE4E: virAllocN (viralloc.c:190)
    by 0x5F3E4FA: x86ModelCopySignatures (cpu_x86.c:990)
    by 0x5F3E60F: x86ModelCopy (cpu_x86.c:1008)
    by 0x5F3E7CB: x86ModelFromCPU (cpu_x86.c:1068)
    by 0x5F4397E: virCPUx86Translate (cpu_x86.c:2922)
    by 0x5F3C239: virCPUTranslate (cpu.c:927)
    by 0x57CE7A1: qemuProcessUpdateGuestCPU (qemu_process.c:5870)
    ...

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/cpu/cpu_x86.c

index 92941d12872c0d600df45e51e05e7f903d09c81c..add889c9a8a265d756e565bc37e52f7305d9391a 100644 (file)
@@ -987,6 +987,9 @@ x86ModelCopySignatures(virCPUx86ModelPtr dst,
 {
     size_t i;
 
+    if (src->nsignatures == 0)
+        return 0;
+
     if (VIR_ALLOC_N(dst->signatures, src->nsignatures) < 0)
         return -1;