From nobody Sat May 18 12:04:57 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=1672827151; cv=none; d=zohomail.com; s=zohoarc; b=Ab16OREOWIpjLf3QHgX8fyUVXXqhrqu546DKKrTtyXbv0WxN25na15B+6Mry/5VoBv/AnVShLckZ78pGWsNXQZtTBDIdErcEMgKZYMo1wHSz17KNaB0yVa/eVHm0hM+g04sx6KHwxqiYTnXhvORKgYZmwx4c3NRMgsR5psUDA9E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1672827151; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=jj2OQmniUKGyTj9hVV+r/3Y1f8fCx7Jiti7ers12lmY=; b=JVHqkBM/4mDvj9k6MQEIybbRgV3jo3seLp0j1E7+3JKJfuTnpIg+A5By0SUDfFCppHuDEjnXh71Ys4oJKA1tPPEq2ApTOJi+u3/kpXHsBFFMocyztE6n80j3+QzURwDNaLu6MOMKQz0LQYQX88eDVS+j8uGqTF4c3TQyiIH99IM= 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 1672827151476729.3234603407667; Wed, 4 Jan 2023 02:12:31 -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-266-txLPUAXrN-S4amJofM4MTA-1; Wed, 04 Jan 2023 05:12:28 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EBAE21C087A3; Wed, 4 Jan 2023 10:12:25 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FC91140EBF5; Wed, 4 Jan 2023 10:12:25 +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 E02701946589; Wed, 4 Jan 2023 10:12:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3335E1946587 for ; Wed, 4 Jan 2023 10:12:15 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2F4EC40C2004; Wed, 4 Jan 2023 10:12:15 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC23540C2064 for ; Wed, 4 Jan 2023 10:12:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672827150; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=jj2OQmniUKGyTj9hVV+r/3Y1f8fCx7Jiti7ers12lmY=; b=IzWdun/3y/xwoRLxt67rMsfI9nJK1RzPa9YFwTnbN9jSy8kgxOGiJhRgRUz5uKLRlUXMcR FQULFYeSZ5yaDTXTGnzGzsYDUAO81UFehzdMhPULtovPlvZy8rHbvxhKbAIzH/MVxA9qGe OPi2fA86dnnq3wOaW9O9VY+y8Sf7bys= X-MC-Unique: txLPUAXrN-S4amJofM4MTA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] security_selinux: Set and restore /dev/sgx_* labels Date: Wed, 4 Jan 2023 11:12:12 +0100 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.7 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: 1672827152731100001 Content-Type: text/plain; charset="utf-8"; x-default="true" For SGX type of memory, QEMU needs to open and talk to /dev/sgx_vepc and /dev/sgx_provision files. But we do not set nor restore SELinux labels on these files when starting a guest. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/security/security_dac.c | 3 --- src/security/security_manager.h | 4 ++++ src/security/security_selinux.c | 24 ++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 917fcf76a3..abfc07218e 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -47,9 +47,6 @@ VIR_LOG_INIT("security.security_dac"); =20 #define SECURITY_DAC_NAME "dac" -#define DEV_SEV "/dev/sev" -#define DEV_SGX_VEPC "/dev/sgx_vepc" -#define DEV_SGX_PROVISION "/dev/sgx_provision" =20 typedef struct _virSecurityDACData virSecurityDACData; struct _virSecurityDACData { diff --git a/src/security/security_manager.h b/src/security/security_manage= r.h index 60597ffc0a..4afdcc167b 100644 --- a/src/security/security_manager.h +++ b/src/security/security_manager.h @@ -23,6 +23,10 @@ #include "domain_conf.h" #include "vircommand.h" =20 +#define DEV_SEV "/dev/sev" +#define DEV_SGX_VEPC "/dev/sgx_vepc" +#define DEV_SGX_PROVISION "/dev/sgx_provision" + typedef struct _virSecurityManager virSecurityManager; =20 typedef enum { diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 93cc12407a..c4832e1bfc 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1577,10 +1577,21 @@ virSecuritySELinuxSetMemoryLabel(virSecurityManager= *mgr, return -1; break; =20 + case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: + seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX= _NAME); + if (!seclabel || !seclabel->relabel) + return 0; + + if (virSecuritySELinuxSetFilecon(mgr, DEV_SGX_VEPC, + seclabel->imagelabel, true) < 0 || + virSecuritySELinuxSetFilecon(mgr, DEV_SGX_PROVISION, + seclabel->imagelabel, true) < 0) + return -1; + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: - case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: case VIR_DOMAIN_MEMORY_MODEL_LAST: break; } @@ -1607,9 +1618,18 @@ virSecuritySELinuxRestoreMemoryLabel(virSecurityMana= ger *mgr, ret =3D virSecuritySELinuxRestoreFileLabel(mgr, mem->nvdimmPath, t= rue); break; =20 + case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: + seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX= _NAME); + if (!seclabel || !seclabel->relabel) + return 0; + + ret =3D virSecuritySELinuxRestoreFileLabel(mgr, DEV_SGX_VEPC, true= ); + if (virSecuritySELinuxRestoreFileLabel(mgr, DEV_SGX_PROVISION, tru= e) < 0) + ret =3D -1; + break; + case VIR_DOMAIN_MEMORY_MODEL_DIMM: case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: - case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: case VIR_DOMAIN_MEMORY_MODEL_NONE: case VIR_DOMAIN_MEMORY_MODEL_LAST: ret =3D 0; --=20 2.38.2