From nobody Sun May 5 22:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551965892234164.56988094998496; Thu, 7 Mar 2019 05:38:12 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93370C4ED3; Thu, 7 Mar 2019 13:38:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3CDA25D783; Thu, 7 Mar 2019 13:38:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EC1E83FB11; Thu, 7 Mar 2019 13:38:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x27Dc8aT023922 for ; Thu, 7 Mar 2019 08:38:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id ED58B5C545; Thu, 7 Mar 2019 13:38:08 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A5145C1B5; Thu, 7 Mar 2019 13:38:05 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 7 Mar 2019 14:38:03 +0100 Message-Id: <1b89c419b4cee94fbc790b321ddc0f0d09ddca49.1551965883.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: jdenemar@redhat.com Subject: [libvirt] [PATCH] cpu: Don't access invalid memory in virCPUx86Translate X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 07 Mar 2019 13:38:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Michal Privoznik Reviewed-by: Jiri Denemark --- src/cpu/cpu_x86.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 92941d1287..c8697819ab 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -987,6 +987,9 @@ x86ModelCopySignatures(virCPUx86ModelPtr dst, { size_t i; =20 + if (src->nsignatures =3D=3D 0) + return 0; + if (VIR_ALLOC_N(dst->signatures, src->nsignatures) < 0) return -1; =20 @@ -2926,7 +2929,7 @@ virCPUx86Translate(virCPUDefPtr cpu, virCPUx86DataAddCPUIDInt(&model->data, &model->vendor->cpuid) < 0) goto cleanup; =20 - if (model->signatures && + if (model->nsignatures && x86DataAddSignature(&model->data, model->signatures[0]) < 0) goto cleanup; =20 --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list