From nobody Fri May 17 10:34:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1671608651; cv=none; d=zohomail.com; s=zohoarc; b=Kfvs7z823vppoFBXjr87v2l2JPEuKm76p0DD5lvEt1QwpcMu47ntKMyQ1ucs6dNYvPo0DqvWDFrfTKSoiiN/zx5rXDZgL8jLG2YCq9GVaGY6ujvMwCbN+BvSsHNVcF3DbWfhKKKInO+TUg2w/UCbwkaEXkT7F9XQuIvXykXhqtg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671608651; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VGJHzocZrK2VX94GH8KBE1UH5i9YT9j7xqbUtm3Cl/I=; b=AdDtuXWoGcCNjinO3Ltz/7dVL9oCl6VQB3DJ0xjYRBcTjnkBOHsBCJ3BQBRv0fWuDTwpaTg/kY/l3wF+tR+Vi2ptxk+5n+6EvoI+RcNQkSJN9ZCknTc7UMcU5JqhIGiBe/eQEzIanSK9jiTFaYdGavnlRbFXvPiM14Sv73TSoTw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1671608651094299.7648907827721; Tue, 20 Dec 2022 23:44:11 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-588-QePJ6_y0M-aWknOSnDLkbg-1; Wed, 21 Dec 2022 02:44:06 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B1B8C85C6E2; Wed, 21 Dec 2022 07:44:03 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B18A02166B26; Wed, 21 Dec 2022 07:44:00 +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 851EB19465A8; Wed, 21 Dec 2022 07:44:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 16ABB19465A4 for ; Wed, 21 Dec 2022 07:44:00 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 05A1AC16028; Wed, 21 Dec 2022 07:44:00 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2629C16027 for ; Wed, 21 Dec 2022 07:43:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671608650; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=VGJHzocZrK2VX94GH8KBE1UH5i9YT9j7xqbUtm3Cl/I=; b=HaBOFnOLhyK0husibiDe/nXsZIxmDULZ7+EUXcCMH7MwW4Oi2tOp8WAAaHzXmJhxBxPSeh WnQ1wsXKR2+KBgjIn9+F6FHDC1tXuMiqGQx31R3TjHtEHIii1nPIY0vufJ6WUK4wHnG5ea exYj72HTxokiT+Yuh1mS6q9MHDis8+Y= X-MC-Unique: QePJ6_y0M-aWknOSnDLkbg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/7] qemu_security: Rework qemuSecurityCleanupTPMEmulator() Date: Wed, 21 Dec 2022 08:43:51 +0100 Message-Id: <71d69cfae9a92f97ae68376c6f3adb27fa0c2b0d.1671608556.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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 3.1 on 10.11.54.6 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: 1671608652897100004 Content-Type: text/plain; charset="utf-8"; x-default="true" Currently, qemuSecurityCleanupTPMEmulator() returns nothing which means a caller (well, there's only one - qemuExtTPMStop()) can't produce a warning when restoring seclabels on TPM state failed. True, qemuSecurityCleanupTPMEmulator() does report a warning itself, but only in one specific error path. Make the function return an integer, just like the rest of qemuSecurity*Restore() functions. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/qemu/qemu_security.c | 21 ++++++++++++--------- src/qemu/qemu_security.h | 6 +++--- src/qemu/qemu_tpm.c | 3 ++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_security.c b/src/qemu/qemu_security.c index def4061488..a0b78764e5 100644 --- a/src/qemu/qemu_security.c +++ b/src/qemu/qemu_security.c @@ -576,26 +576,29 @@ qemuSecurityStartTPMEmulator(virQEMUDriver *driver, } =20 =20 -void +int qemuSecurityCleanupTPMEmulator(virQEMUDriver *driver, virDomainObj *vm, bool restoreTPMStateLabel) { qemuDomainObjPrivate *priv =3D vm->privateData; - bool transactionStarted =3D false; + int ret =3D -1; =20 - if (virSecurityManagerTransactionStart(driver->securityManager) >=3D 0) - transactionStarted =3D true; + if (virSecurityManagerTransactionStart(driver->securityManager) < 0) + goto cleanup; =20 - virSecurityManagerRestoreTPMLabels(driver->securityManager, - vm->def, restoreTPMStateLabel); + if (virSecurityManagerRestoreTPMLabels(driver->securityManager, + vm->def, restoreTPMStateLabel) = < 0) + goto cleanup; =20 - if (transactionStarted && - virSecurityManagerTransactionCommit(driver->securityManager, + if (virSecurityManagerTransactionCommit(driver->securityManager, -1, priv->rememberOwner) < 0) - VIR_WARN("Unable to run security manager transaction"); + goto cleanup; =20 + ret =3D 0; + cleanup: virSecurityManagerTransactionAbort(driver->securityManager); + return ret; } =20 =20 diff --git a/src/qemu/qemu_security.h b/src/qemu/qemu_security.h index 969a47fc17..0b19f48ef2 100644 --- a/src/qemu/qemu_security.h +++ b/src/qemu/qemu_security.h @@ -94,9 +94,9 @@ int qemuSecurityStartTPMEmulator(virQEMUDriver *driver, int *exitstatus, int *cmdret); =20 -void qemuSecurityCleanupTPMEmulator(virQEMUDriver *driver, - virDomainObj *vm, - bool restoreTPMStateLabel); +int qemuSecurityCleanupTPMEmulator(virQEMUDriver *driver, + virDomainObj *vm, + bool restoreTPMStateLabel); =20 int qemuSecuritySetSavedStateLabel(virQEMUDriver *driver, virDomainObj *vm, diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index f2edaf5eaa..8778d43913 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -1143,7 +1143,8 @@ qemuExtTPMStop(virQEMUDriver *driver, if (outgoingMigration || qemuTPMHasSharedStorage(vm->def)) restoreTPMStateLabel =3D false; =20 - qemuSecurityCleanupTPMEmulator(driver, vm, restoreTPMStateLabel); + if (qemuSecurityCleanupTPMEmulator(driver, vm, restoreTPMStateLabel) <= 0) + VIR_WARN("Unable to restore labels on TPM state and/or log file"); } =20 =20 --=20 2.38.2 From nobody Fri May 17 10:34:10 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=1671608704; cv=none; d=zohomail.com; s=zohoarc; b=Yy6O+hTp808zWdvp5ElInNPDJR/2AuBQJGE8yPO5BqzdWDnaDUemjovyEPrIKrRnVtgF5qIanc4KZqsXpcKDzSUVl8t1iH/UoSwk/+JRH9+PeXw3DyfXoHQzJH9uhdyPOuvuB0UcFjCmY1fzm5eBAWDcFLsuXg7XAwysor3R2+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671608704; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ys/j7LSoN7eF12ejAO4rBK2luOuIxCmKEEwbKxRY3Lk=; b=MRn3Zhp/9dsg7+plIYPqkNHIN6IOzjR3V4CMAu8bs5hjLjzQY1OtJpLBiDtxjSEsgg8VpNQnO6Yj3DRRO4wOo3C3HihAKeOJk0cJR60C+RsYN3laSlMyC+rh7G64NZ/V7g3/bKMQWVWkekZWemBzYZThwtjb51bGWG9quzbDUDc= 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 1671608704952444.24248924058566; Tue, 20 Dec 2022 23:45:04 -0800 (PST) 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-584-UoKWZkpuNlSiUuYG46-82w-1; Wed, 21 Dec 2022 02:44:06 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 71FD13815D47; Wed, 21 Dec 2022 07:44:03 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 102A24085722; Wed, 21 Dec 2022 07:44:03 +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 CE9AF1946A78; Wed, 21 Dec 2022 07:44:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AE3621946A6D for ; Wed, 21 Dec 2022 07:44:00 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 92E5BC158BB; Wed, 21 Dec 2022 07:44:00 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B6C0C16027 for ; Wed, 21 Dec 2022 07:44:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671608704; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Ys/j7LSoN7eF12ejAO4rBK2luOuIxCmKEEwbKxRY3Lk=; b=YNEATwaBGVWuE2Xq2h1QndQzdBi0RRjZHaJI1iGx+ZA7VHnIcn1gzkfrS+Mf9DZnnze54q i8ToAKE+WQIi2V2j3sDpIClG9+Ctm72PGckib1W3iWfAdso1JRgjhg3Hg5ha/Vi3px++iB 3cxkP7uPtRn1eSQ9ibeXCFbPUp1CJNs= X-MC-Unique: UoKWZkpuNlSiUuYG46-82w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/7] qemu_security: Rename qemuSecurityCleanupTPMEmulator() Date: Wed, 21 Dec 2022 08:43:52 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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 3.1 on 10.11.54.2 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: 1671608707104100001 Content-Type: text/plain; charset="utf-8"; x-default="true" The qemuSecurityCleanupTPMEmulator() function calls virSecurityManagerRestoreTPMLabels() and thus the proper name is qemuSecurityRestoreTPMLabels(). Rename it. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/qemu/qemu_security.c | 6 +++--- src/qemu/qemu_security.h | 6 +++--- src/qemu/qemu_tpm.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_security.c b/src/qemu/qemu_security.c index a0b78764e5..82d686b0e3 100644 --- a/src/qemu/qemu_security.c +++ b/src/qemu/qemu_security.c @@ -577,9 +577,9 @@ qemuSecurityStartTPMEmulator(virQEMUDriver *driver, =20 =20 int -qemuSecurityCleanupTPMEmulator(virQEMUDriver *driver, - virDomainObj *vm, - bool restoreTPMStateLabel) +qemuSecurityRestoreTPMLabels(virQEMUDriver *driver, + virDomainObj *vm, + bool restoreTPMStateLabel) { qemuDomainObjPrivate *priv =3D vm->privateData; int ret =3D -1; diff --git a/src/qemu/qemu_security.h b/src/qemu/qemu_security.h index 0b19f48ef2..b6f917a62f 100644 --- a/src/qemu/qemu_security.h +++ b/src/qemu/qemu_security.h @@ -94,9 +94,9 @@ int qemuSecurityStartTPMEmulator(virQEMUDriver *driver, int *exitstatus, int *cmdret); =20 -int qemuSecurityCleanupTPMEmulator(virQEMUDriver *driver, - virDomainObj *vm, - bool restoreTPMStateLabel); +int qemuSecurityRestoreTPMLabels(virQEMUDriver *driver, + virDomainObj *vm, + bool restoreTPMStateLabel); =20 int qemuSecuritySetSavedStateLabel(virQEMUDriver *driver, virDomainObj *vm, diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index 8778d43913..200ff0de6f 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -1143,7 +1143,7 @@ qemuExtTPMStop(virQEMUDriver *driver, if (outgoingMigration || qemuTPMHasSharedStorage(vm->def)) restoreTPMStateLabel =3D false; =20 - if (qemuSecurityCleanupTPMEmulator(driver, vm, restoreTPMStateLabel) <= 0) + if (qemuSecurityRestoreTPMLabels(driver, vm, restoreTPMStateLabel) < 0) VIR_WARN("Unable to restore labels on TPM state and/or log file"); } =20 --=20 2.38.2 From nobody Fri May 17 10:34:10 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=1671608651; cv=none; d=zohomail.com; s=zohoarc; b=SJhNYaguf4e82Fg0aCQa0W37YJmemuvQ/suswcUDga+r4Q/KxZwxwSUrzQghQx9oGG/4Ab8oHszo5Rm92sIqn0AYYHhoNpGWMtIgSbS9hNkR6GiH9Ru5s9HeztQYoQOIeVkjVCnXm3ZPN7YdJc7wFar/Xeuk5T00UIGfZScf+CU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671608651; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NiUY3FPNaYEObOXM+BlynTrRWNC9J8+H+kg2SFRurx0=; b=PMkb1w5VIzm+iVS6YSMbXTWasNQ1PcaJjr6Kp4AbKBaaR984xeMpVZbWi2T2PRYk8R5VRt3yuqTdkuih6D/ltQROuNClYv3Qb5bt/jAvPmcDQt/rG8n0qHmj58DnhvggSemAisVJiTuepomKsDxRBvWkpWxBPZ2cveB+3CbsxfA= 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 1671608651286583.1775584477978; Tue, 20 Dec 2022 23:44:11 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-495-JHyxhC5TMiSGqhD9St368A-1; Wed, 21 Dec 2022 02:44:07 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D1A5F802C1D; Wed, 21 Dec 2022 07:44:03 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCBA240C945A; Wed, 21 Dec 2022 07:44:03 +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 230931947049; Wed, 21 Dec 2022 07:44:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 49BFE1946A78 for ; Wed, 21 Dec 2022 07:44:01 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2BBF0C16027; Wed, 21 Dec 2022 07:44:01 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8F2FC158BB for ; Wed, 21 Dec 2022 07:44:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671608650; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NiUY3FPNaYEObOXM+BlynTrRWNC9J8+H+kg2SFRurx0=; b=RNCAFaqn7ScVNme3DmcH3s8Rl9Hy2HxCNgTKUDmRtMFb0Hln2nt8y297JgnyeVuZ+3gxK1 p9JeNuWR7q0NeOn0oJWtmjfQ5wo5MEswEVbZ5+hC7zDApnHIw15KdDLUFZGN4ZDoKEAaY3 fid8GcmfGyBczPuqw+40I13vwgtlqOE= X-MC-Unique: JHyxhC5TMiSGqhD9St368A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/7] qemu_security: Introduce qemuSecuritySetTPMLabels() Date: Wed, 21 Dec 2022 08:43:53 +0100 Message-Id: <80478fb565f3acfbf8557ddc5468fad2e1a8e6c1.1671608556.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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 3.1 on 10.11.54.2 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: 1671608652874100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Now that we have qemuSecurityRestoreTPMLabels() we might as well have qemuSecuritySetTPMLabels(). The aim here is to remove qemuSecurityStartTPMEmulator() which couples two separate things into a single function call. Therefore, introduce qemuSecuritySetTPMLabels() which does only set seclabels on the TPM state. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/qemu/qemu_security.c | 26 ++++++++++++++++++++++++++ src/qemu/qemu_security.h | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/src/qemu/qemu_security.c b/src/qemu/qemu_security.c index 82d686b0e3..daf01bb803 100644 --- a/src/qemu/qemu_security.c +++ b/src/qemu/qemu_security.c @@ -576,6 +576,32 @@ qemuSecurityStartTPMEmulator(virQEMUDriver *driver, } =20 =20 +int +qemuSecuritySetTPMLabels(virQEMUDriver *driver, + virDomainObj *vm, + bool setTPMStateLabel) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + int ret =3D -1; + + if (virSecurityManagerTransactionStart(driver->securityManager) < 0) + goto cleanup; + + if (virSecurityManagerSetTPMLabels(driver->securityManager, + vm->def, setTPMStateLabel) < 0) + goto cleanup; + + if (virSecurityManagerTransactionCommit(driver->securityManager, + -1, priv->rememberOwner) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virSecurityManagerTransactionAbort(driver->securityManager); + return ret; +} + + int qemuSecurityRestoreTPMLabels(virQEMUDriver *driver, virDomainObj *vm, diff --git a/src/qemu/qemu_security.h b/src/qemu/qemu_security.h index b6f917a62f..198f8ef0d4 100644 --- a/src/qemu/qemu_security.h +++ b/src/qemu/qemu_security.h @@ -94,6 +94,10 @@ int qemuSecurityStartTPMEmulator(virQEMUDriver *driver, int *exitstatus, int *cmdret); =20 +int qemuSecuritySetTPMLabels(virQEMUDriver *driver, + virDomainObj *vm, + bool setTPMStateLabel); + int qemuSecurityRestoreTPMLabels(virQEMUDriver *driver, virDomainObj *vm, bool restoreTPMStateLabel); --=20 2.38.2 From nobody Fri May 17 10:34:10 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=1671608707; cv=none; d=zohomail.com; s=zohoarc; b=R2FzG0wJj6wU83vrgaRNJJI0baPORD5PR7c8qbbsUZmg82ruX4ChmkzVO1PRMSmQ+RedirQAa1824ulQHjfT/oXJI1W8KU4E3OLF2k7kx8z31u3Oyl0NpZ9Obqx86yrdCndCi6j9119dG6IaI5AvR6CC0N1gkcQwxrrF1Tcs3+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671608707; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RVEWZZZZBL7r2gRzBn+AXjVzivbvMO1PT5yo6LqOPPM=; b=IQ/fxt5r0bCQAgiIk6RBoRoAtuAu05OBljit3GWtdmTmd34Ve3WVPiFSAhAGqQ+PVhWW6s+fYd8JIdkSsDv7LxKdVTdyQ3qXFT97B+vC+9fBgRuQZkoYeOYzBRdVCq5iqE6ZmB/0HULlJc2TBcWgwJvYZAeoDf4iQv1J7Z25Zvs= 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 1671608707512312.3047677794808; Tue, 20 Dec 2022 23:45:07 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-638-B4mfUjOpODyUe5LePPqe6w-1; Wed, 21 Dec 2022 02:44:07 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 91079857F5C; Wed, 21 Dec 2022 07:44:04 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44759C1602F; Wed, 21 Dec 2022 07:44:04 +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 D6D3919465BA; Wed, 21 Dec 2022 07:44:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C988719465A4 for ; Wed, 21 Dec 2022 07:44:01 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B9518C16028; Wed, 21 Dec 2022 07:44:01 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6216FC16027 for ; Wed, 21 Dec 2022 07:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671608706; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=RVEWZZZZBL7r2gRzBn+AXjVzivbvMO1PT5yo6LqOPPM=; b=NHTKWG8c6LcYCs29XFSdJZLoydgddBPXNpSlXdFYLbBXcOdQ/1W7W7bT4cIFRCimP9ANwJ NvQ2CtQ6d/4a2GNMBgq15j+ZUS8U/GQuqMP342VbNVeJlaGTj7BUxWfHdIf0YzJxU8bEhh Xe3N8AGIZzfZasnh7ZcITbpUDqw9jxY= X-MC-Unique: B4mfUjOpODyUe5LePPqe6w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/7] qemu_tpm: Restore TPM labels on failed start Date: Wed, 21 Dec 2022 08:43:54 +0100 Message-Id: <535aff3882118aa06b291c807aa8592928ecc840.1671608556.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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 3.1 on 10.11.54.8 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: 1671608709126100005 Content-Type: text/plain; charset="utf-8"; x-default="true" If swtpm binary fails to start after successful exec() (e.g. it fails to initialize itself), the seclabels set in qemuSecurityStartTPMEmulator() are not restored. This is due to lacking qemuSecurityRestoreTPMLabels() call in the error path. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/qemu/qemu_tpm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index 200ff0de6f..03055002cb 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -927,6 +927,7 @@ qemuTPMEmulatorStart(virQEMUDriver *driver, virTimeBackOffVar timebackoff; const unsigned long long timeout =3D 1000; /* ms */ bool setTPMStateLabel =3D true; + bool teardownlabel =3D false; int cmdret =3D 0; pid_t pid =3D -1; =20 @@ -970,6 +971,7 @@ qemuTPMEmulatorStart(virQEMUDriver *driver, * already reported error. */ goto error; } + teardownlabel =3D true; =20 if (virPidFileReadPath(pidfile, &pid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1012,6 +1014,8 @@ qemuTPMEmulatorStart(virQEMUDriver *driver, virProcessKillPainfully(pid, true); if (pidfile) unlink(pidfile); + if (teardownlabel) + qemuSecurityRestoreTPMLabels(driver, vm, setTPMStateLabel); return -1; } =20 --=20 2.38.2 From nobody Fri May 17 10:34:10 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=1671608772; cv=none; d=zohomail.com; s=zohoarc; b=czYc47iYcAaxgm2ZS7MyuCyTsBLzgJtI7QMPkfdpKz7aTMZ5qnNK7Xc+AHMZLOy3oP+r5pSK9m9l/gi2O6uSr9F+ysYkR+K3EWE3CNgamxzx3D0fQuOVpcZbwHpDxu+xM9TYNsYQudA2xLNBwX8CbZG8riIy16KcLgd7oR2Vayo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671608772; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SWUtLJzv5DN0Fmhy+zXNIcuKFrpIiVasxl4l8L4OooE=; b=cxeeZCup7d/ml+mM6Abg9BBtWQRc6j4R0L7eyDj0rAEcJYVZ/U7OEJcSDhVgOQ4onqeeBG9nxHQEyJlGWNROe99iEteUf8hf6utrbtwABtAbXJ/Ho8x+Hm/C6WZSg+YSJsJsyUhDs423wfqGwa8kM1JHg9nEDeW8nyZhdVGCp14= 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 1671608772338730.5935354154149; Tue, 20 Dec 2022 23:46:12 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-259-d40upYK4PBKwbvw3bt4HjA-1; Wed, 21 Dec 2022 02:44:09 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1BAD1180999F; Wed, 21 Dec 2022 07:44:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1FE0492D8A; Wed, 21 Dec 2022 07:44:04 +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 5D26119465B7; Wed, 21 Dec 2022 07:44:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6F36C19465B9 for ; Wed, 21 Dec 2022 07:44:02 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5362EC158BB; Wed, 21 Dec 2022 07:44:02 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF837C16027 for ; Wed, 21 Dec 2022 07:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671608771; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=SWUtLJzv5DN0Fmhy+zXNIcuKFrpIiVasxl4l8L4OooE=; b=AB0NkUKmtyyx3H0uFmg+6++pwTgpZDZDSRsQ5zxZ+Ji2bu64Zu8qD7mPRMCVzwGjjxxBXE vz8NIdp2wHQUORgutkNL5mk/lMBcqjUjGNH+UuvNqgzEA+dILtOeYq61ogKMT+egAEQUiA zyukSk8V57+Ths2J3mrSWW0OglNfOTY= X-MC-Unique: d40upYK4PBKwbvw3bt4HjA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/7] qemu_tpm: Open code qemuSecurityStartTPMEmulator() Date: Wed, 21 Dec 2022 08:43:55 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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 3.1 on 10.11.54.10 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: 1671608773469100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When starting swtpm binary, the qemuSecurityStartTPMEmulator() is called which sets seclabel on the TPM state and then uses qemuSecurityCommandRun() to execute the swtpm binary with proper seclabel. Well, the aim is to ditch qemuSecurityStartTPMEmulator() because it entangles two distinct operations. Just call functions for them separately. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/qemu/qemu_tpm.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index 03055002cb..b2748eb6a4 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -927,7 +927,6 @@ qemuTPMEmulatorStart(virQEMUDriver *driver, virTimeBackOffVar timebackoff; const unsigned long long timeout =3D 1000; /* ms */ bool setTPMStateLabel =3D true; - bool teardownlabel =3D false; int cmdret =3D 0; pid_t pid =3D -1; =20 @@ -960,18 +959,18 @@ qemuTPMEmulatorStart(virQEMUDriver *driver, setTPMStateLabel =3D false; } =20 - if (qemuSecurityStartTPMEmulator(driver, vm, cmd, - cfg->swtpm_user, cfg->swtpm_group, - setTPMStateLabel, NULL, &cmdret) < 0)= { + if (qemuSecuritySetTPMLabels(driver, vm, setTPMStateLabel) < 0) + return -1; + + if (qemuSecurityCommandRun(driver, vm, cmd, cfg->swtpm_user, + cfg->swtpm_group, NULL, &cmdret) < 0) goto error; - } =20 if (cmdret < 0) { - /* virCommandRun() hidden in qemuSecurityStartTPMEmulator() + /* virCommandRun() hidden in qemuSecurityCommandRun() * already reported error. */ goto error; } - teardownlabel =3D true; =20 if (virPidFileReadPath(pidfile, &pid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1014,8 +1013,7 @@ qemuTPMEmulatorStart(virQEMUDriver *driver, virProcessKillPainfully(pid, true); if (pidfile) unlink(pidfile); - if (teardownlabel) - qemuSecurityRestoreTPMLabels(driver, vm, setTPMStateLabel); + qemuSecurityRestoreTPMLabels(driver, vm, setTPMStateLabel); return -1; } =20 --=20 2.38.2 From nobody Fri May 17 10:34:10 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=1671608773; cv=none; d=zohomail.com; s=zohoarc; b=gE34i1EckobFZWbYeaRfiTiDZWsRzMF3YxC6LBSzM2w4z52yUwmfEHXsC85zkqNm+ET2aYpKEMtGJnSfeX7DZQYvG00PFl24GR19mGiJHbaBJZBhVrgcNq7awAbJ8xCC6iww97j5znDUcyTizySJLcUli8DwfDbT38MT9+6fmJc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671608773; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jtApnREUcglgJoMAOIgHbXWJQSXL/uQnO/HRB+8MI5U=; b=M0/3QVhRoCJ7L5pIc94PwVnKflHRGnnV66xMQfp/9W324DG6dBvZUjOiG38LFRNuRhzf6Rf6y1g7JHitBaD/W7yWgZnIS12djnxdNMOoYLTDT1xnRYkGFecYRzTomyRRJGu3X3kXYMnxylhhRysY/Rtpfri6lXNoegMorDOD6PA= 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 167160877301145.68175212319056; Tue, 20 Dec 2022 23:46:13 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-317-eeSYn-opNuic0MezFU_28g-1; Wed, 21 Dec 2022 02:44:09 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F1DD48588F7; Wed, 21 Dec 2022 07:44:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC374492C1B; Wed, 21 Dec 2022 07:44:05 +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 D2CE619465A8; Wed, 21 Dec 2022 07:44:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0638619465B7 for ; Wed, 21 Dec 2022 07:44:03 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DFF66C1602B; Wed, 21 Dec 2022 07:44:02 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 887FFC16027 for ; Wed, 21 Dec 2022 07:44:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671608771; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=jtApnREUcglgJoMAOIgHbXWJQSXL/uQnO/HRB+8MI5U=; b=VqWUZd5DczZW8GQwlCGPxg/HBm3js5jIx7okqtUVbvanCnUDvo6oeEcr/drexOz9jwaLZD vkGoOQP6LC65L3dhY0GbD+/LjDmUUW9O5aeM+IFEMdB093o+aZGLvRiHolqKiuQpiBkfzt sTQVi0WpuEYYTi2fmT2lnQrVul8dL/g= X-MC-Unique: eeSYn-opNuic0MezFU_28g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 6/7] qemu_security: Drop qemuSecurityStartTPMEmulator() Date: Wed, 21 Dec 2022 08:43:56 +0100 Message-Id: <73a2f3f59793f51bd382565eab258d46dde07269.1671608556.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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 3.1 on 10.11.54.9 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: 1671608773483100002 Content-Type: text/plain; charset="utf-8"; x-default="true" After previous cleanup this function is no longer used and thus can be dropped. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/qemu/qemu_security.c | 77 ---------------------------------------- src/qemu/qemu_security.h | 9 ----- 2 files changed, 86 deletions(-) diff --git a/src/qemu/qemu_security.c b/src/qemu/qemu_security.c index daf01bb803..beada669f7 100644 --- a/src/qemu/qemu_security.c +++ b/src/qemu/qemu_security.c @@ -499,83 +499,6 @@ qemuSecurityRestoreNetdevLabel(virQEMUDriver *driver, } =20 =20 -/* - * qemuSecurityStartTPMEmulator: - * - * @driver: the QEMU driver - * @vm: the domain object - * @cmd: the command to run - * @uid: the uid to run the emulator - * @gid: the gid to run the emulator - * @setTPMStateLabel: whether TPM state should be labelled, or just logfile - * @existstatus: pointer to int returning exit status of process - * @cmdret: pointer to int returning result of virCommandRun - * - * Start the TPM emulator with appropriate labels. Apply security - * labels to files first. - * This function returns -1 on security setup error, 0 if all the - * setup was done properly. In case the virCommand failed to run - * 0 is returned but cmdret is set appropriately with the process - * exitstatus also set. - */ -int -qemuSecurityStartTPMEmulator(virQEMUDriver *driver, - virDomainObj *vm, - virCommand *cmd, - uid_t uid, - gid_t gid, - bool setTPMStateLabel, - int *exitstatus, - int *cmdret) -{ - qemuDomainObjPrivate *priv =3D vm->privateData; - int ret =3D -1; - bool transactionStarted =3D false; - - if (virSecurityManagerTransactionStart(driver->securityManager) < 0) - return -1; - transactionStarted =3D true; - - if (virSecurityManagerSetTPMLabels(driver->securityManager, - vm->def, setTPMStateLabel) < 0) { - virSecurityManagerTransactionAbort(driver->securityManager); - return -1; - } - - if (virSecurityManagerTransactionCommit(driver->securityManager, - -1, priv->rememberOwner) < 0) - goto cleanup_abort; - transactionStarted =3D false; - - if (qemuSecurityCommandRun(driver, vm, cmd, uid, gid, exitstatus, cmdr= et) < 0) - goto cleanup; - - ret =3D 0; - - if (*cmdret < 0) - goto cleanup; - - return 0; - - cleanup: - if (!transactionStarted && - virSecurityManagerTransactionStart(driver->securityManager) >=3D 0) - transactionStarted =3D true; - - virSecurityManagerRestoreTPMLabels(driver->securityManager, - vm->def, setTPMStateLabel); - - if (transactionStarted && - virSecurityManagerTransactionCommit(driver->securityManager, - -1, priv->rememberOwner) < 0) - VIR_WARN("Unable to run security manager transaction"); - - cleanup_abort: - virSecurityManagerTransactionAbort(driver->securityManager); - return ret; -} - - int qemuSecuritySetTPMLabels(virQEMUDriver *driver, virDomainObj *vm, diff --git a/src/qemu/qemu_security.h b/src/qemu/qemu_security.h index 198f8ef0d4..8d1c6b38c3 100644 --- a/src/qemu/qemu_security.h +++ b/src/qemu/qemu_security.h @@ -85,15 +85,6 @@ int qemuSecurityRestoreNetdevLabel(virQEMUDriver *driver, virDomainObj *vm, virDomainNetDef *net); =20 -int qemuSecurityStartTPMEmulator(virQEMUDriver *driver, - virDomainObj *vm, - virCommand *cmd, - uid_t uid, - gid_t gid, - bool setTPMStateLabel, - int *exitstatus, - int *cmdret); - int qemuSecuritySetTPMLabels(virQEMUDriver *driver, virDomainObj *vm, bool setTPMStateLabel); --=20 2.38.2 From nobody Fri May 17 10:34:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1671608655; cv=none; d=zohomail.com; s=zohoarc; b=a9ZHm0rtGWCiM4SIYBxmO7yOKgkieQ92iSgTZqtpSKdLe6x5SpqyzUz3THWSXMI7eUc3BJTw3mU6DHnewYUeh3kyxMsqWO/1o5bo2Oo4TuYimQ1eDbW1AvXk7YX6kvh3O5x1qNCNOVx4Efu3ZvwcazT3tg52fZdCp1HoH45ry7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671608655; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cLj0Ng/dZ53Saa9qOT3yh5CsS5PGc3dmQRGEdmVvdsA=; b=GqQXwV1WRyp95aT+iaqMzsmL0HLWzVzhV+Z3ya7HlBEzb6V76jQdYrBBzsgRdIDetsIaMvXDt4+WC3ZpExeQFlPLUQAjVC/bRH6ZnJXwHzO3ySLt/WL23HLW0XZWAyeEUK4BPbMcuzj6YuDWPd4FwSvvjimC4CobxmEV6MW/8jk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1671608655171803.3955679944007; Tue, 20 Dec 2022 23:44:15 -0800 (PST) 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-658-F3UD6UZ6NnOFM8mMSBOefQ-1; Wed, 21 Dec 2022 02:44:08 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5C1492999B4D; Wed, 21 Dec 2022 07:44:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44A1E492B00; Wed, 21 Dec 2022 07:44:05 +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 99A7C19465A8; Wed, 21 Dec 2022 07:44:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8318B1946A72 for ; Wed, 21 Dec 2022 07:44:03 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 78BDDC16029; Wed, 21 Dec 2022 07:44:03 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21976C16027 for ; Wed, 21 Dec 2022 07:44:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671608654; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=cLj0Ng/dZ53Saa9qOT3yh5CsS5PGc3dmQRGEdmVvdsA=; b=PKCn2/fOBodQmOj6vusGB/Dk/ajSPs55zlBekpQKc0LJZmct9AugmHr1xIMoQS6n5aaNbJ PusUTcjgnzll/YzIt5cGPX7gHlmoU5znWF9riwyIvNKABc1S+ZrIxSxcFQzSZOzlKlNKqB /6yg+pfnDxNugEqlMif2h7rARBNdNec= X-MC-Unique: F3UD6UZ6NnOFM8mMSBOefQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 7/7] docs: Recommend static seclabels for migration on shared storage Date: Wed, 21 Dec 2022 08:43:57 +0100 Message-Id: <5ac0d7f5d59330fd33db9ab190a7368a8e24ce8f.1671608556.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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 3.1 on 10.11.54.10 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: 1671608656914100001 Content-Type: text/plain; charset="utf-8"; x-default="true" There are some network FSs (ceph, CIFS) that propagate XATTTs properly and thus SELinux labels too. In such case using dynamic seclabels would get in the way of migration as new seclabel is assigned to the domain on the destination and thus two processes with different labels (the source and the destination QEMU/helper process) would try to access the same file. One of them is necessarily going to be denied access. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- docs/drvqemu.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/drvqemu.rst b/docs/drvqemu.rst index bbd51066a1..fa23912937 100644 --- a/docs/drvqemu.rst +++ b/docs/drvqemu.rst @@ -294,6 +294,13 @@ use the 'context' option when mounting the filesystem = to set the default label to ``system_u:object_r:virt_image_t``. In the case of NFS, there is an alternative option, of enabling the ``virt_use_nfs`` SELinux boolean. =20 +There are some network filesystems, however, that propagate SELinux labels +properly, just like a local filesystem (e.g. ceph of CIFS). In such case, +dynamic labelling (described below) might prevent migration of a virtual +machine as new unique SELinux label is assigned to the virtual machine on = the +migration destination side. Users are advised to use static labels (````). + SELinux sVirt confinement ~~~~~~~~~~~~~~~~~~~~~~~~~ =20 --=20 2.38.2