From nobody Fri May 3 19:14:01 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 ARC-Seal: i=1; a=rsa-sha256; t=1571155519; cv=none; d=zoho.com; s=zohoarc; b=Ft2vuRyUInud00YxPUBDhhP9RDaOygdnUARCX7R/SyY313xLCW+HmlwNRDuaE2v7gyZAOGvr/vBH7Rslyr/AKp5OdPNAsCYhLr0uC06MjzAq4GaAGeifZzKss9fcHU1Tktn8holJceJSR9m24csF/LSLG8d1O5uMLfBzWiaUSBE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571155519; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=YGJ83AQ96AqO1i+Q+x40AR85vJ/WALvPMV75xhfyTsQ=; b=loZKzDkgEXIl5M+Xs+zVTZ9uMAV+T0p4GApTjQPvnxeJFdAic2xIq88sJ5ucE7DWcZFzVGBFo+ZVs1f0YO/OJolAIIYjgMO7DPt+tA3zcXlJFo0E80qoog5gJkgBwXMRAvNLyNn1JdnWt27T6GUbUYo2tuayJjtpZL9jPSMRqXs= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1571155519154220.19211156091546; Tue, 15 Oct 2019 09:05:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C3A7C3082E42; Tue, 15 Oct 2019 16:05:16 +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 14F1360BE2; Tue, 15 Oct 2019 16:05:16 +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 69F824E58A; Tue, 15 Oct 2019 16:05:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9FG19u0028387 for ; Tue, 15 Oct 2019 12:01:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id A70F5194BB; Tue, 15 Oct 2019 16:01:09 +0000 (UTC) Received: from worklaptop.bos.redhat.com (dhcp-17-175.bos.redhat.com [10.18.17.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36E4119C58; Tue, 15 Oct 2019 16:01:06 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Tue, 15 Oct 2019 12:01:38 -0400 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Jonathon Jongsma Subject: [libvirt] [PATCH] qemu: caps: Use unique key for domCaps caching 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 15 Oct 2019 16:05:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" When searching qemuCaps->domCapsCache for existing domCaps data, we check for a matching pair of arch+virttype+machine+emulator. However for the hash table key we only use the machine string. So if the cache already contains: x86_64 + kvm + pc + /usr/bin/qemu-kvm But a new VM is defined with x86_64 + qemu + pc + /usr/bin/qemu-kvm We correctly fail to find matching cached domCaps, but then attempt to use a colliding key with virHashAddEntry Fix this by building a hash key from the 4 values, not just machine Signed-off-by: Cole Robinson Reviewed-by: Daniel Henrique Barboza Reviewed-by: Jonathon Jongsma --- qemu_domain.c validation should be affected, but it is covered up by another bug, fixed here: https://www.redhat.com/archives/libvir-list/2019-October/msg00708.html src/qemu/qemu_conf.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 08cd784054..64ac8cbdd3 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1396,6 +1396,8 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr d= river, domCaps =3D virHashSearch(domCapsCache, virQEMUDriverSearchDomcaps, &data, NULL); if (!domCaps) { + VIR_AUTOFREE(char *) key =3D NULL; + /* hash miss, build new domcaps */ if (!(domCaps =3D virDomainCapsNew(data.path, data.machine, data.arch, data.virttype))) @@ -1406,7 +1408,14 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr = driver, cfg->firmwares, cfg->nfirmwares) < 0) return NULL; =20 - if (virHashAddEntry(domCapsCache, machine, domCaps) < 0) + if (virAsprintf(&key, "%d:%d:%s:%s", + data.arch, + data.virttype, + NULLSTR(data.machine), + NULLSTR(data.path)) < 0) + return NULL; + + if (virHashAddEntry(domCapsCache, key, domCaps) < 0) return NULL; } =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list