From nobody Thu Dec 26 10:26:32 2024 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1729606710254147.58771747354; Tue, 22 Oct 2024 07:18:30 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2CB8BCEC; Tue, 22 Oct 2024 10:18:29 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1930B19EA; Tue, 22 Oct 2024 10:16:28 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 778F816B1; Tue, 22 Oct 2024 10:16:23 -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 0D3F316B1 for ; Tue, 22 Oct 2024 10:15:59 -0400 (EDT) Received: from mx-prod-mc-02.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-389-0Im0tnOMNl6aaWRWVXW_eg-1; Tue, 22 Oct 2024 10:15:56 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6FBE31955EA7; Tue, 22 Oct 2024 14:15:55 +0000 (UTC) Received: from localhost (unknown [10.39.208.14]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4363919560AE; Tue, 22 Oct 2024 14:15:53 +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=-2.3 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE 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=1729606559; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rMonhzy9aZ8TarCLINDHuMzKu9ISEt/lHyb0dh1FeGo=; b=NywXjdCy4QjgeSZzNkJTmZ8j4S3r+KdLsfS2RKNQ5BnhspHOhI4b+ClriPv3Bwqx1eHAQi yIWPse8psfpDtF8A/ST28i7MkQ8GYZ9BjC5gwnuncrfC0szDH3zkmxqM8FL+hdVAedEu/W XG3Ign4gP+TYaiusvbGz3QxvCOJThR8= X-MC-Unique: 0Im0tnOMNl6aaWRWVXW_eg-1 From: marcandre.lureau@redhat.com To: devel@lists.libvirt.org Subject: [PATCH v5 6/6] qemu: explicit swtpm state locking Date: Tue, 22 Oct 2024 18:15:21 +0400 Message-ID: <20241022141521.2000577-7-marcandre.lureau@redhat.com> In-Reply-To: <20241022141521.2000577-1-marcandre.lureau@redhat.com> References: <20241022141521.2000577-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: XNMZBOPMJWHRZEDVCOUXDKMDKCZUBL4N X-Message-ID-Hash: XNMZBOPMJWHRZEDVCOUXDKMDKCZUBL4N X-MailFrom: marcandre.lureau@redhat.com X-Mailman-Rule-Hits: nonmember-moderation 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 CC: stefanb@us.ibm.com, mkletzan@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= 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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1729606711870116600 Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau With upcoming v0.10 swtpm (commit https://github.com/stefanberger/swtpm/commit/aa483aeb6df87ed56ccf3d5778d6fd= 8019089bda), file locking with "lock" option is now supported and reflected in "tpmstate-opt-lock" capability. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- src/qemu/qemu_tpm.c | 11 +++++++++-- src/util/virtpm.c | 1 + src/util/virtpm.h | 1 + tests/testutilsqemu.c | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index bf94b6ac0d..edd10ca2f6 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -344,16 +344,23 @@ static char * qemuTPMGetSwtpmSetupStateArg(const virDomainTPMSourceType source_type, const char *source_path) { + const char *lock =3D ",lock"; + + if (!virTPMSwtpmSetupCapsGet(VIR_TPM_SWTPM_SETUP_FEATURE_TPMSTATE_OPT_= LOCK)) { + VIR_WARN("This swtpm version doesn't support explicit locking"); + lock =3D ""; + } + switch (source_type) { case VIR_DOMAIN_TPM_SOURCE_TYPE_FILE: /* the file:// prefix is supported since swtpm_setup 0.7.0 */ /* assume the capability check for swtpm is redundant. */ - return g_strdup_printf("file://%s", source_path); + return g_strdup_printf("file://%s%s", source_path, lock); case VIR_DOMAIN_TPM_SOURCE_TYPE_DIR: case VIR_DOMAIN_TPM_SOURCE_TYPE_DEFAULT: case VIR_DOMAIN_TPM_SOURCE_TYPE_LAST: default: - return g_strdup_printf("%s", source_path); + return g_strdup_printf("%s%s", source_path, lock); } } =20 diff --git a/src/util/virtpm.c b/src/util/virtpm.c index 298caaad80..8dcd3f90d9 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -52,6 +52,7 @@ VIR_ENUM_IMPL(virTPMSwtpmSetupFeature, "cmdarg-reconfigure-pcr-banks", "tpm-1.2", "tpm-2.0", + "tpmstate-opt-lock", ); =20 /** diff --git a/src/util/virtpm.h b/src/util/virtpm.h index 99dbcc1dc8..279cb7e976 100644 --- a/src/util/virtpm.h +++ b/src/util/virtpm.h @@ -44,6 +44,7 @@ typedef enum { VIR_TPM_SWTPM_SETUP_FEATURE_CMDARG_RECONFIGURE_PCR_BANKS, VIR_TPM_SWTPM_SETUP_FEATURE_TPM_1_2, VIR_TPM_SWTPM_SETUP_FEATURE_TPM_2_0, + VIR_TPM_SWTPM_SETUP_FEATURE_TPMSTATE_OPT_LOCK, =20 VIR_TPM_SWTPM_SETUP_FEATURE_LAST } virTPMSwtpmSetupFeature; diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 4daee432e5..f40bfa873c 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -71,6 +71,7 @@ virTPMSwtpmSetupCapsGet(virTPMSwtpmSetupFeature cap) case VIR_TPM_SWTPM_SETUP_FEATURE_CMDARG_CREATE_CONFIG_FILES: case VIR_TPM_SWTPM_SETUP_FEATURE_TPM12_NOT_NEED_ROOT: case VIR_TPM_SWTPM_SETUP_FEATURE_CMDARG_RECONFIGURE_PCR_BANKS: + case VIR_TPM_SWTPM_SETUP_FEATURE_TPMSTATE_OPT_LOCK: case VIR_TPM_SWTPM_SETUP_FEATURE_LAST: break; } --=20 2.47.0