From nobody Fri May 17 01:43:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 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=1660244241; cv=none; d=zohomail.com; s=zohoarc; b=fg8sciSr3952zutQ5dHKX+qp42/K06s/Ue+/T4tm/KZi6mRw8/5xskPyX/DJPtfqJ7dPW3YrQ6p/w4I8LgWe1sGiuIrmNdPsym+zHs7QcssZWenCbhhBc7KPehmEk/LPZZbAOaz5GPwTEGuJNNCe/IXNi2TW84CdZpmjlTLlu9g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660244241; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=YKtIPcoz8NA7Oxk9FSvEz+hlhYMACoGvTPacXvdQjkA=; b=CTiEtbDV6hIQdrWNOj97rnagZEboTXBMjp9SOYihLwuu12egnB/lJ5WWBLyn9tsFE/6SrPGRUAx2kf/CH9EtScluygLKaIWoK1EBD7oeJtGTklxl9EVPRbKa8PuqWOzKCtASEhOO9jtK4mlDauy5Uwj9PQOMWBLZ+qx58NUiTpg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1660244241381682.3598278661534; Thu, 11 Aug 2022 11:57:21 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-189-_quiQMzxPTC1kLyNbik78A-1; Thu, 11 Aug 2022 14:57:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2FBC93C1C009; Thu, 11 Aug 2022 18:57:11 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D25B1121314; Thu, 11 Aug 2022 18:57:11 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C60A31946A42; Thu, 11 Aug 2022 18:57:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5496E1946A41 for ; Thu, 11 Aug 2022 18:57:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 12A852026985; Thu, 11 Aug 2022 18:57:06 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC3A72026D64 for ; Thu, 11 Aug 2022 18:57:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660244239; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=YKtIPcoz8NA7Oxk9FSvEz+hlhYMACoGvTPacXvdQjkA=; b=RZlYYKvVjW50MQw2+hBoiI+AjL3ZeeS54dUU2JTEbprbT3oZM+cin8UIg0S09dVNrSFDYO DC9t4tP99FkrFONNiTWW/NMigxE/dkkrBaLizQPZBlMbfby3HnN0YeFs9rh9dSmA1ySkXk /0PG60+St9LZpS7v9cY02Iv/WYD3c5g= X-MC-Unique: _quiQMzxPTC1kLyNbik78A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] qemu_tpm: Don't crash if qemuTPMPcrBankBitmapToStr(NULL) Date: Thu, 11 Aug 2022 20:57:02 +0200 Message-Id: <21c818049f5f64f1f8f947e80ff20394e825e612.1660244222.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1660244242799100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Historically, the tpm->data.emulator.activePcrBanks member was an unsigned int but since it was used as a bitmap it was converted to virBitmap type instead. Now, the virBitmap is allocated inside of virDomainTPMDefParseXML() but only if was found with at last one child element. Otherwise it stays NULL. Fast forward to starting a domain with TPM 2.0 and no configured. Eventually, qemuTPMEmulatorBuildCommand() is called, which subsequently calls qemuTPMEmulatorReconfigure() and finally qemuTPMPcrBankBitmapToStr() passing the NULL value. Before rewrite to virBitmap this function would return NULL for empty activePcrBanks but now, well, now it crashes. Fixes: 52c7c31c8038aa31d502f59a40e4fb4ba9f61113 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_tpm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index c08b0851da..584c787b70 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -449,6 +449,9 @@ qemuTPMPcrBankBitmapToStr(virBitmap *activePcrBanks) g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; ssize_t bank =3D -1; =20 + if (!activePcrBanks) + return NULL; + while ((bank =3D virBitmapNextSetBit(activePcrBanks, bank)) > -1) virBufferAsprintf(&buf, "%s,", virDomainTPMPcrBankTypeToString(ban= k)); =20 --=20 2.35.1