From nobody Fri Jan 3 02:57:05 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=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 1729535051565333.6550471444832; Mon, 21 Oct 2024 11:24:11 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 840E61807; Mon, 21 Oct 2024 14:24:10 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2DCD715EF; Mon, 21 Oct 2024 14:23:53 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DF4DB158A; Mon, 21 Oct 2024 14:23:49 -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 DDA1E183D for ; Mon, 21 Oct 2024 14:23:41 -0400 (EDT) Received: from mx-prod-mc-04.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-267-IctlAejpOAKpYpCWxhsFvQ-1; Mon, 21 Oct 2024 14:23:37 -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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 91FED19560BC; Mon, 21 Oct 2024 18:23:35 +0000 (UTC) Received: from localhost (unknown [10.39.208.14]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CF6001956088; Mon, 21 Oct 2024 18:23:33 +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=1729535021; 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=RVGSmf0Q4cNYlAcqje+ay6RWC2afrLVy73WAodQTkoQ=; b=K32DnvLT/LikoSmNeBuN6ziPPUfcs9ogK/JPSQPcvYyamk4jcjwaW7taUCMJr7vtI5UZmz pPyAt03KoF5HB6Gm+bDdTGNKfvIqs45q26SvAcK6ill+bfyY8BDUnwfcLUtwl8wW3YrO1B 3Ci36Km+NfNdFBAQvBD1l0SqjGjLHs4= X-MC-Unique: IctlAejpOAKpYpCWxhsFvQ-1 From: marcandre.lureau@redhat.com To: devel@lists.libvirt.org Subject: [PATCH v4 1/6] util: check swtpm nvram-backend-{dir,file} capabilities Date: Mon, 21 Oct 2024 22:23:20 +0400 Message-ID: <20241021182325.1670505-2-marcandre.lureau@redhat.com> In-Reply-To: <20241021182325.1670505-1-marcandre.lureau@redhat.com> References: <20241021182325.1670505-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: BMMEENQE522FMVHOM2YKMETSZMWBK4VD X-Message-ID-Hash: BMMEENQE522FMVHOM2YKMETSZMWBK4VD 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: mkletzan@redhat.com, stefanb@us.ibm.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: 1729535052508116600 Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- src/util/virtpm.c | 2 ++ src/util/virtpm.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/util/virtpm.c b/src/util/virtpm.c index 81fd6166cf..298caaad80 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -40,6 +40,8 @@ VIR_ENUM_IMPL(virTPMSwtpmFeature, VIR_TPM_SWTPM_FEATURE_LAST, "cmdarg-pwd-fd", "cmdarg-migration", + "nvram-backend-dir", + "nvram-backend-file", ); =20 VIR_ENUM_IMPL(virTPMSwtpmSetupFeature, diff --git a/src/util/virtpm.h b/src/util/virtpm.h index fb330effa8..99dbcc1dc8 100644 --- a/src/util/virtpm.h +++ b/src/util/virtpm.h @@ -31,6 +31,8 @@ bool virTPMHasSwtpm(void); typedef enum { VIR_TPM_SWTPM_FEATURE_CMDARG_PWD_FD, VIR_TPM_SWTPM_FEATURE_CMDARG_MIGRATION, + VIR_TPM_SWTPM_FEATURE_NVRAM_BACKEND_DIR, + VIR_TPM_SWTPM_FEATURE_NVRAM_BACKEND_FILE, =20 VIR_TPM_SWTPM_FEATURE_LAST } virTPMSwtpmFeature; --=20 2.47.0 From nobody Fri Jan 3 02:57:05 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=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 1729535085023545.0762341476244; Mon, 21 Oct 2024 11:24:45 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EC3851892; Mon, 21 Oct 2024 14:24:43 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id EF4651651; Mon, 21 Oct 2024 14:23:58 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 93075159C; Mon, 21 Oct 2024 14:23:54 -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 4E1101575 for ; Mon, 21 Oct 2024 14:23:49 -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-261-eBTSRGYIPVeHCcKo1hB3bg-1; Mon, 21 Oct 2024 14:23:43 -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 DB1491956080; Mon, 21 Oct 2024 18:23:40 +0000 (UTC) Received: from localhost (unknown [10.39.208.14]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CEFC91956088; Mon, 21 Oct 2024 18:23:39 +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=1729535028; 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=wICdfOS1sdturXArUeFQIdOaDCTd1uIkfXZBtGBYNH8=; b=ctH30qViXySbqSOqzG28up6mootV79OvV8MZxut7W144ZfWn9sXW7DuIT8h1e9cqQCOk5Y dUGf2k9vrJAisATBCX61e0m3OQK79w/2sIul3KkeBQnUNLSk+lqoMXkLU8P0KBwEjschV4 kPMuWpBjTli93auIf8OOmJOY3vOQ7Us= X-MC-Unique: eBTSRGYIPVeHCcKo1hB3bg-1 From: marcandre.lureau@redhat.com To: devel@lists.libvirt.org Subject: [PATCH v4 2/6] tpm: rename 'storagepath' to 'source_path' Date: Mon, 21 Oct 2024 22:23:21 +0400 Message-ID: <20241021182325.1670505-3-marcandre.lureau@redhat.com> In-Reply-To: <20241021182325.1670505-1-marcandre.lureau@redhat.com> References: <20241021182325.1670505-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: DQ7NYCHXTCKKIM66WFZAH3SN6GSPUN76 X-Message-ID-Hash: DQ7NYCHXTCKKIM66WFZAH3SN6GSPUN76 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: mkletzan@redhat.com, stefanb@us.ibm.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: 1729535086760116600 Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Mechanically replace existing 'storagepath' with 'source_path', as the following patches introduce configuration. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- src/conf/domain_conf.c | 2 +- src/conf/domain_conf.h | 2 +- src/qemu/qemu_tpm.c | 46 ++++++++++++++++----------------- src/security/security_selinux.c | 6 ++--- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6d7dee7956..284a3815b3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3461,7 +3461,7 @@ void virDomainTPMDefFree(virDomainTPMDef *def) break; case VIR_DOMAIN_TPM_TYPE_EMULATOR: virObjectUnref(def->data.emulator.source); - g_free(def->data.emulator.storagepath); + g_free(def->data.emulator.source_path); g_free(def->data.emulator.logfile); virBitmapFree(def->data.emulator.activePcrBanks); break; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index a15af4fae3..6b27322e3e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1478,7 +1478,7 @@ struct _virDomainTPMDef { struct { virDomainTPMVersion version; virDomainChrSourceDef *source; - char *storagepath; + char *source_path; char *logfile; unsigned int debug; unsigned char secretuuid[VIR_UUID_BUFLEN]; diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index 749e4232b9..2d9cd59643 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -173,8 +173,8 @@ qemuTPMEmulatorCreateStorage(virDomainTPMDef *tpm, uid_t swtpm_user, gid_t swtpm_group) { - const char *storagepath =3D tpm->data.emulator.storagepath; - g_autofree char *swtpmStorageDir =3D g_path_get_dirname(storagepath); + const char *source_path =3D tpm->data.emulator.source_path; + g_autofree char *swtpmStorageDir =3D g_path_get_dirname(source_path); =20 /* allow others to cd into this dir */ if (g_mkdir_with_parents(swtpmStorageDir, 0711) < 0) { @@ -186,19 +186,19 @@ qemuTPMEmulatorCreateStorage(virDomainTPMDef *tpm, =20 *created =3D false; =20 - if (!virFileExists(storagepath) || - virDirIsEmpty(storagepath, true) > 0) + if (!virFileExists(source_path) || + virDirIsEmpty(source_path, true) > 0) *created =3D true; =20 - if (virDirCreate(storagepath, 0700, swtpm_user, swtpm_group, + if (virDirCreate(source_path, 0700, swtpm_user, swtpm_group, VIR_DIR_CREATE_ALLOW_EXIST) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not create directory %1$s as %2$u:%3$d"), - storagepath, swtpm_user, swtpm_group); + source_path, swtpm_user, swtpm_group); return -1; } =20 - if (virFileChownFiles(storagepath, swtpm_user, swtpm_group) < 0) + if (virFileChownFiles(source_path, swtpm_user, swtpm_group) < 0) return -1; =20 return 0; @@ -214,7 +214,7 @@ qemuTPMEmulatorCreateStorage(virDomainTPMDef *tpm, static void qemuTPMEmulatorDeleteStorage(virDomainTPMDef *tpm) { - g_autofree char *path =3D g_path_get_dirname(tpm->data.emulator.storag= epath); + g_autofree char *path =3D g_path_get_dirname(tpm->data.emulator.source= _path); =20 ignore_value(virFileDeleteTree(path)); } @@ -343,7 +343,7 @@ qemuTPMVirCommandAddEncryption(virCommand *cmd, /* * qemuTPMEmulatorRunSetup * - * @storagepath: path to the directory for TPM state + * @source_path: path to the directory for TPM state * @vmname: the name of the VM * @vmuuid: the UUID of the VM * @privileged: whether we are running in privileged mode @@ -360,7 +360,7 @@ qemuTPMVirCommandAddEncryption(virCommand *cmd, * certificates for it. */ static int -qemuTPMEmulatorRunSetup(const char *storagepath, +qemuTPMEmulatorRunSetup(const char *source_path, const char *vmname, const unsigned char *vmuuid, bool privileged, @@ -413,7 +413,7 @@ qemuTPMEmulatorRunSetup(const char *storagepath, =20 if (!incomingMigration) { virCommandAddArgList(cmd, - "--tpm-state", storagepath, + "--tpm-state", source_path, "--vmid", vmid, "--logfile", logfile, "--createek", @@ -424,7 +424,7 @@ qemuTPMEmulatorRunSetup(const char *storagepath, NULL); } else { virCommandAddArgList(cmd, - "--tpm-state", storagepath, + "--tpm-state", source_path, "--logfile", logfile, "--overwrite", NULL); @@ -465,7 +465,7 @@ qemuTPMPcrBankBitmapToStr(virBitmap *activePcrBanks) * qemuTPMEmulatorReconfigure * * - * @storagepath: path to the directory for TPM state + * @source_path: path to the directory for TPM state * @swtpm_user: The userid to switch to when setting up the TPM; * typically this should be the uid of 'tss' or 'root' * @swtpm_group: The group id to switch to @@ -478,7 +478,7 @@ qemuTPMPcrBankBitmapToStr(virBitmap *activePcrBanks) * Reconfigure the active PCR banks of a TPM 2. */ static int -qemuTPMEmulatorReconfigure(const char *storagepath, +qemuTPMEmulatorReconfigure(const char *source_path, uid_t swtpm_user, gid_t swtpm_group, virBitmap *activePcrBanks, @@ -510,7 +510,7 @@ qemuTPMEmulatorReconfigure(const char *storagepath, return -1; =20 virCommandAddArgList(cmd, - "--tpm-state", storagepath, + "--tpm-state", source_path, "--logfile", logfile, "--pcr-banks", activePcrBanksStr, "--reconfigure", @@ -570,7 +570,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm, /* Do not create storage and run swtpm_setup on incoming migration over * shared storage */ - on_shared_storage =3D virFileIsSharedFS(tpm->data.emulator.storagepath= , sharedFilesystems) =3D=3D 1; + on_shared_storage =3D virFileIsSharedFS(tpm->data.emulator.source_path= , sharedFilesystems) =3D=3D 1; if (incomingMigration && on_shared_storage) create_storage =3D false; =20 @@ -582,7 +582,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm, secretuuid =3D tpm->data.emulator.secretuuid; =20 if (created && - qemuTPMEmulatorRunSetup(tpm->data.emulator.storagepath, vmname, vm= uuid, + qemuTPMEmulatorRunSetup(tpm->data.emulator.source_path, vmname, vm= uuid, privileged, swtpm_user, swtpm_group, tpm->data.emulator.logfile, tpm->data.emulator.version, @@ -590,7 +590,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm, goto error; =20 if (!incomingMigration && - qemuTPMEmulatorReconfigure(tpm->data.emulator.storagepath, + qemuTPMEmulatorReconfigure(tpm->data.emulator.source_path, swtpm_user, swtpm_group, tpm->data.emulator.activePcrBanks, tpm->data.emulator.logfile, @@ -610,7 +610,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm, =20 virCommandAddArg(cmd, "--tpmstate"); virCommandAddArgFormat(cmd, "dir=3D%s,mode=3D0600", - tpm->data.emulator.storagepath); + tpm->data.emulator.source_path); =20 virCommandAddArg(cmd, "--log"); if (tpm->data.emulator.debug !=3D 0) @@ -723,8 +723,8 @@ qemuTPMEmulatorInitPaths(virDomainTPMDef *tpm, =20 virUUIDFormat(uuid, uuidstr); =20 - if (!tpm->data.emulator.storagepath && - !(tpm->data.emulator.storagepath =3D + if (!tpm->data.emulator.source_path && + !(tpm->data.emulator.source_path =3D qemuTPMEmulatorStorageBuildPath(swtpmStorageDir, uuidstr, tpm->data.emulator.version))) return -1; @@ -759,7 +759,7 @@ qemuTPMEmulatorCleanupHost(virQEMUDriver *driver, * storage. */ if (outgoingMigration && - virFileIsSharedFS(tpm->data.emulator.storagepath, cfg->sharedFiles= ystems) =3D=3D 1) + virFileIsSharedFS(tpm->data.emulator.source_path, cfg->sharedFiles= ystems) =3D=3D 1) return; =20 /* @@ -1040,7 +1040,7 @@ qemuTPMHasSharedStorage(virQEMUDriver *driver, =20 switch (tpm->type) { case VIR_DOMAIN_TPM_TYPE_EMULATOR: - return virFileIsSharedFS(tpm->data.emulator.storagepath, + return virFileIsSharedFS(tpm->data.emulator.source_path, cfg->sharedFilesystems) =3D=3D 1; case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: case VIR_DOMAIN_TPM_TYPE_EXTERNAL: diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 8f567d5488..18daa521d1 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -3726,7 +3726,7 @@ virSecuritySELinuxSetTPMLabels(virSecurityManager *mg= r, =20 if (setTPMStateLabel) { ret =3D virSecuritySELinuxSetFileLabels(mgr, - def->tpms[i]->data.emula= tor.storagepath, + def->tpms[i]->data.emula= tor.source_path, seclabel); } =20 @@ -3756,14 +3756,14 @@ virSecuritySELinuxRestoreTPMLabels(virSecurityManag= er *mgr, =20 if (restoreTPMStateLabel) { ret =3D virSecuritySELinuxRestoreFileLabels(mgr, - def->tpms[i]->data.e= mulator.storagepath); + def->tpms[i]->data.e= mulator.source_path); } else { /* Even if we're not restoring the original label for the * TPM state directory, we should still forget any * remembered label so that a subsequent attempt at TPM * startup will not fail due to the state directory being * considered as still in use */ - virSecuritySELinuxForgetLabels(def->tpms[i]->data.emulator.sto= ragepath); + virSecuritySELinuxForgetLabels(def->tpms[i]->data.emulator.sou= rce_path); } =20 if (ret =3D=3D 0 && --=20 2.47.0 From nobody Fri Jan 3 02:57:05 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=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 1729535112294854.8145454019932; Mon, 21 Oct 2024 11:25:12 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2D0E818B8; Mon, 21 Oct 2024 14:25:11 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E7018156A; Mon, 21 Oct 2024 14:24:00 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id A711A15CD; Mon, 21 Oct 2024 14:23:54 -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 130721587 for ; Mon, 21 Oct 2024 14:23:49 -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-471-0XFVVNAVM9KFy--fftGydg-1; Mon, 21 Oct 2024 14:23:47 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 4CFD0195609E; Mon, 21 Oct 2024 18:23:46 +0000 (UTC) Received: from localhost (unknown [10.39.208.14]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D2A3E300018D; Mon, 21 Oct 2024 18:23:44 +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=1729535028; 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=Ij8N1P8ia94KK6V1FY2ktrJ1xMGKHmRU5fALmy2Qvdc=; b=MVdHGtzio+6axPPJJhJN5uQ1K/pkPiTJHMYmqHDhictiBQCNG04j5CVU1zrJ6AOlUH02tU +MLoNrw7s96LefqWZwUP6JoWsC/wfHUKP3rupCmQB85X+kwR70tziu2p9DIfEIQQpc+lbd TAtlZa1YWH6wz5IoAQiCmWAkQYGJt1c= X-MC-Unique: 0XFVVNAVM9KFy--fftGydg-1 From: marcandre.lureau@redhat.com To: devel@lists.libvirt.org Subject: [PATCH v4 3/6] schema: add TPM emulator Date: Mon, 21 Oct 2024 22:23:22 +0400 Message-ID: <20241021182325.1670505-4-marcandre.lureau@redhat.com> In-Reply-To: <20241021182325.1670505-1-marcandre.lureau@redhat.com> References: <20241021182325.1670505-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: X3NEX5QKRZ4FQIC2QM7XVPF362YXBIJH X-Message-ID-Hash: X3NEX5QKRZ4FQIC2QM7XVPF362YXBIJH 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: mkletzan@redhat.com, stefanb@us.ibm.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: 1729535112881116600 Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Learn to parse a file path for the TPM state. Signed-off-by: Marc-Andr=C3=A9 Lureau --- docs/formatdomain.rst | 19 ++++++++++++++ src/conf/domain_conf.c | 28 +++++++++++++++++++++ src/conf/domain_conf.h | 9 +++++++ src/conf/schemas/domaincommon.rng | 14 +++++++++++ tests/qemuxmlconfdata/tpm-emulator-tpm2.xml | 1 + 5 files changed, 71 insertions(+) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index e6f09a728f..d4feb4421c 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -8174,6 +8174,25 @@ Example: usage of the TPM Emulator The default version used depends on the combination of hypervisor, guest architecture, TPM model and backend. =20 +``source`` + The ``source`` element specifies the location of the TPM state storage = . This + element only works with the ``emulator`` backend. + + If not specified, the storage configuration is left to libvirt discreti= on. + + This element requires that swtpm v0.7 or later is installed. + + The following attributes are supported: + + ``type`` + The type of storage. It's possible to provide "file" to utilize a si= ngle + file or block device where the TPM state will be stored. + + ``path`` + The path to the TPM state storage. + + :since:`Since v10.8.0` + ``persistent_state`` The ``persistent_state`` attribute indicates whether 'swtpm' TPM state = is kept or not when a transient domain is powered off or undefined. This diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 284a3815b3..9dd8b6b55d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1322,6 +1322,12 @@ VIR_ENUM_IMPL(virDomainTPMVersion, "2.0", ); =20 +VIR_ENUM_IMPL(virDomainTPMSourceType, + VIR_DOMAIN_TPM_SOURCE_TYPE_LAST, + "default", + "file", +); + VIR_ENUM_IMPL(virDomainTPMPcrBank, VIR_DOMAIN_TPM_PCR_BANK_LAST, "sha1", @@ -10784,6 +10790,7 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt, int nbackends; int nnodes; size_t i; + xmlNodePtr source_node =3D NULL; g_autofree char *path =3D NULL; g_autofree char *secretuuid =3D NULL; g_autofree char *persistent_state =3D NULL; @@ -10857,6 +10864,22 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt, def->data.emulator.hassecretuuid =3D true; } =20 + source_node =3D virXPathNode("./backend/source", ctxt); + if (source_node) { + if (virXMLPropEnum(source_node, "type", + virDomainTPMSourceTypeTypeFromString, + VIR_XML_PROP_NONZERO, + &def->data.emulator.source_type) < 0) + goto error; + path =3D virXMLPropString(source_node, "path"); + if (!path) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing TPM source path")); + goto error; + } + def->data.emulator.source_path =3D g_steal_pointer(&path); + } + persistent_state =3D virXMLPropString(backends[0], "persistent_sta= te"); if (persistent_state) { if (virStringParseYesNo(persistent_state, @@ -25070,6 +25093,11 @@ virDomainTPMDefFormat(virBuffer *buf, =20 virXMLFormatElement(&backendChildBuf, "active_pcr_banks", NULL= , &activePcrBanksBuf); } + if (def->data.emulator.source_type !=3D VIR_DOMAIN_TPM_SOURCE_TYPE= _DEFAULT) { + virBufferAsprintf(&backendChildBuf, "data= .emulator.source_type)); + virBufferEscapeString(&backendChildBuf, " path=3D'%s'/>\n", de= f->data.emulator.source_path); + } break; case VIR_DOMAIN_TPM_TYPE_EXTERNAL: if (def->data.external.source->type =3D=3D VIR_DOMAIN_CHR_TYPE_UNI= X) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 6b27322e3e..7a70f68177 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1463,6 +1463,13 @@ typedef enum { VIR_DOMAIN_TPM_PCR_BANK_LAST } virDomainPcrBank; =20 +typedef enum { + VIR_DOMAIN_TPM_SOURCE_TYPE_DEFAULT =3D 0, + VIR_DOMAIN_TPM_SOURCE_TYPE_FILE, + + VIR_DOMAIN_TPM_SOURCE_TYPE_LAST +} virDomainTPMSourceType; + #define VIR_DOMAIN_TPM_DEFAULT_DEVICE "/dev/tpm0" =20 struct _virDomainTPMDef { @@ -1478,6 +1485,7 @@ struct _virDomainTPMDef { struct { virDomainTPMVersion version; virDomainChrSourceDef *source; + virDomainTPMSourceType source_type; char *source_path; char *logfile; unsigned int debug; @@ -4277,6 +4285,7 @@ VIR_ENUM_DECL(virDomainRNGBackend); VIR_ENUM_DECL(virDomainTPMModel); VIR_ENUM_DECL(virDomainTPMBackend); VIR_ENUM_DECL(virDomainTPMVersion); +VIR_ENUM_DECL(virDomainTPMSourceType); VIR_ENUM_DECL(virDomainTPMPcrBank); VIR_ENUM_DECL(virDomainMemoryModel); VIR_ENUM_DECL(virDomainMemoryBackingModel); diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index efb5f00d77..72c8b6c694 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -5923,6 +5923,7 @@ + @@ -5981,6 +5982,19 @@ =20 + + + + + file + + + + + + + + diff --git a/tests/qemuxmlconfdata/tpm-emulator-tpm2.xml b/tests/qemuxmlcon= fdata/tpm-emulator-tpm2.xml index 8a613db456..3d6300f544 100644 --- a/tests/qemuxmlconfdata/tpm-emulator-tpm2.xml +++ b/tests/qemuxmlconfdata/tpm-emulator-tpm2.xml @@ -34,6 +34,7 @@ +