From nobody Mon Sep 8 17:11:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1752754786; cv=none; d=zohomail.com; s=zohoarc; b=GFUZzMLJ2fN63AghEbVOd3T4He7NTKD52Ysxy6RxkPb5ZKPgBqIHSIJz10Mak+50OaR6U8wA+EYXYydeckOFAXV1/FIwlXZqy3wV29WfDgSCi6rH+Kmqs9m9D2ulBwdYgciqxdIS0lq9XzgQQUHkSwvbc7qv8S1fDfOF/atMCsU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752754786; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=PbaC0SOwlb70IE1e0SenrvzrxFzxkUt7UfrkXVzcwMw=; b=RhiOYMH11lpqHp+F6mXZCZyR6VGBP4CI4wIYyRu0d6fTzrxVHcGU+mG9fB9doajSDpHPaFo9N2CV6wUa3k1alKF6mtF+yDkH9jyF2b++k5vHP0fawbuZsxpV4lhHGYHps28adEDNN5fKOpAfBTPqVtoE6FtqUMIO8fwY6KBpie4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1752754785892433.4721952623321; Thu, 17 Jul 2025 05:19:45 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C81EF14B8; Thu, 17 Jul 2025 08:19:44 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 6AF0D146A; Thu, 17 Jul 2025 08:19:07 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B2B9111BC; Thu, 17 Jul 2025 08:19:02 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id DEA7711E3 for ; Thu, 17 Jul 2025 08:19:01 -0400 (EDT) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-435-6oGTKDtBOxmSR8lUiZ5UmQ-1; Thu, 17 Jul 2025 08:19:00 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A541D195FD2B for ; Thu, 17 Jul 2025 12:18:59 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F1BEB19560A0 for ; Thu, 17 Jul 2025 12:18:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752754741; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=RWjzpyWqn23P++0UBsNI6Nvz8ih7ne5GnLsyA1JonWw=; b=GmjkRI5S9Yztz3Bw6L2HfTTNANvwJWNJCNU6Zvikp5wD6+wRkvWDhlyjrBxW6DFvYtELr5 9DDnUKBTIinamBzGQV/DaR8YlcF2dqMi8mkf+ocvB18gvETz8tKH9kI94Psf2n+IsDliw7 qzw/CQSqkJZoOoxyKfWzEaYf1RZrjlA= X-MC-Unique: 6oGTKDtBOxmSR8lUiZ5UmQ-1 X-Mimecast-MFC-AGG-ID: 6oGTKDtBOxmSR8lUiZ5UmQ_1752754739 To: devel@lists.libvirt.org Subject: [PATCH 1/2] qemu: Report system error on failed open() Date: Thu, 17 Jul 2025 14:18:54 +0200 Message-ID: <045cb8a9cf366c0fcc383390a02c993e0ce5c547.1752754566.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: MxCdH3tsQdKa8JSpBoDjamXAISZ4e0vW9hwaaxQoAgQ_1752754739 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: UXLNMQ2KWZ455M7AY7FZVHXD355BR77Y X-Message-ID-Hash: UXLNMQ2KWZ455M7AY7FZVHXD355BR77Y X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1752754788905116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik With a help from coccinelle three places were identified that call virReportError() after failed open() (in qemuDomainWriteMasterKeyFile(), qemuDomainMasterKeyReadFile() and qemuProcessOpenVhostVsock()). The open() syscall does set errno on failure so switch them to virReportSystemError() which may shed more light into the reasons for failure. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_domain.c | 8 ++++---- src/qemu/qemu_process.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 4420940745..963dbd3973 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -515,8 +515,8 @@ qemuDomainWriteMasterKeyFile(virQEMUDriver *driver, return -1; =20 if ((fd =3D open(path, O_WRONLY|O_TRUNC|O_CREAT, 0600)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to open domain master key file for write"= )); + virReportSystemError(errno, "%s", + _("failed to open domain master key file for = write")); return -1; } =20 @@ -580,8 +580,8 @@ qemuDomainMasterKeyReadFile(qemuDomainObjPrivate *priv) } =20 if ((fd =3D open(path, O_RDONLY)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to open domain master key file for read")= ); + virReportSystemError(errno, "%s", + _("failed to open domain master key file for = read")); goto error; } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 82cab3f76e..a2872602e8 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7137,8 +7137,8 @@ qemuProcessOpenVhostVsock(virDomainVsockDef *vsock) int fd; =20 if ((fd =3D open(vsock_path, O_RDWR)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - "%s", _("unable to open vhost-vsock device")); + virReportSystemError(errno, "%s", + _("unable to open vhost-vsock device")); return -1; } =20 --=20 2.49.1 From nobody Mon Sep 8 17:11:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1752754808; cv=none; d=zohomail.com; s=zohoarc; b=B8nww2BiTunNxFk5XD1l6blKfdIOGeuXQYuX4m16lCdq00GB5yXcvZcNVXXkbJVHwnhBVsJm+I8dZIp1ORTls4ikt7ftpJyJDkE0PsQJLyZN9mb+s5VEdRmdlP2IZ/ANc7M5G49GsaNQ3OOsQErJ3mvd7/m+ySjNWIhH+uylYRg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752754808; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=WCXqI6682X4XT5Z/08HV3FrB7l6gGfYk6cUVH3P0Nlw=; b=aX+qGB8y6dyi/LNWaIhyhWuZ86lActb2XPxbXhsCOOmq8ZtevZMZaTPz4tWjxk2WXOLLbXvqCME0bGJM+8RqRkOT3nJDHhyDXxdI9SbXuzsGTXJLXeN1UoiQ8XshkbuOvGwbZnBfTkOzMpN37ebGdS6v00mxVM4ZQ3ZX8SCTOao= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1752754808918716.1780369782514; Thu, 17 Jul 2025 05:20:08 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EA07B1477; Thu, 17 Jul 2025 08:20:07 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5557614E3; Thu, 17 Jul 2025 08:19:10 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 8255011D4; Thu, 17 Jul 2025 08:19:03 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0A5CD11BC for ; Thu, 17 Jul 2025 08:19:03 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-64-UE8IkgoqNZyoo89bnDhmcg-1; Thu, 17 Jul 2025 08:19:01 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C0DF919560A2 for ; Thu, 17 Jul 2025 12:19:00 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 188DE19560A0 for ; Thu, 17 Jul 2025 12:18:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752754742; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=CoOP0pwZSrBt/09tinZF15YWpShpwwabx0xKl2A6mPs=; b=cnyiDkw+mxkQibnr1zM47SRW3Czn6+51igJt+leBRsd6JjrFX283IvCqJ4gOJlTDYj2eHj 7XLdAZaQbUXgXITw2nFMpXqBsGhx7z85aXvBR0NdCMHy7/20J7A3G7MxCTpJnl3DdDu4F1 +E0t67zsZ/jQU/B54xrqDogGg00fZ08= X-MC-Unique: UE8IkgoqNZyoo89bnDhmcg-1 X-Mimecast-MFC-AGG-ID: UE8IkgoqNZyoo89bnDhmcg_1752754740 To: devel@lists.libvirt.org Subject: [PATCH 2/2] qemu_tpm: Don't report uninitialized variable in error message Date: Thu, 17 Jul 2025 14:18:55 +0200 Message-ID: <6f7e3f97eac3fe79cfff2da48d82dbc31bac5d96.1752754566.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: P1PP7Z081bIAVrJz6QrQKoDDE5-kcWKbVAVXnD5HMK0_1752754740 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: YBSAEGTLD7FZHR64WNGAZAO33XUSEF5T X-Message-ID-Hash: YBSAEGTLD7FZHR64WNGAZAO33XUSEF5T X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1752754811156116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Inside to qemu_tpm.c there are three functions that use the same pattern (qemuTPMEmulatorRunSetup(), qemuTPMEmulatorReconfigure() and qemuTPMEmulatorUpdateProfileName()): int exitstatus; ... if (virCommandRun(cmd, &exitstatus) < 0 || exitstatus !=3D 0) { virReportError(..., exitstatus); return -1; } Problem with this pattern is that if virCommandRun() fails then exitstatus is left untouched and a garbage value is then passed to virReportError(). Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_tpm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index b2f76e6b8b..5ff08fccad 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -439,7 +439,7 @@ qemuTPMEmulatorRunSetup(const virDomainTPMEmulatorDef *= emulator, bool incomingMigration) { g_autoptr(virCommand) cmd =3D NULL; - int exitstatus; + int exitstatus =3D -1; char uuid[VIR_UUID_STRING_BUFLEN]; g_autofree char *vmid =3D NULL; g_autofree char *swtpm_setup =3D virTPMGetSwtpmSetup(); @@ -547,7 +547,7 @@ qemuTPMEmulatorReconfigure(const virDomainTPMEmulatorDe= f *emulator, const unsigned char *secretuuid) { g_autoptr(virCommand) cmd =3D NULL; - int exitstatus; + int exitstatus =3D -1; g_autofree char *activePcrBanksStr =3D NULL; g_autofree char *swtpm_setup =3D virTPMGetSwtpmSetup(); g_autofree char *tpm_state =3D qemuTPMGetSwtpmSetupStateArg(emulator->= source_type, @@ -670,7 +670,7 @@ qemuTPMEmulatorUpdateProfileName(virDomainTPMEmulatorDe= f *emulator, g_autofree char *swtpm =3D NULL; virJSONValue *active_profile; const char *profile_name; - int exitstatus; + int exitstatus =3D -1; =20 if (emulator->version !=3D VIR_DOMAIN_TPM_VERSION_2_0 || !virTPMSwtpmCapsGet(VIR_TPM_SWTPM_FEATURE_CMDARG_PRINT_INFO)) --=20 2.49.1