From nobody Mon Feb 9 03:45:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1621446520; cv=none; d=zohomail.com; s=zohoarc; b=XD4WI5kNBIa7sXhniAnr5rrGFueqz8fGvkepUh09rAe3uiBzXhuMP/VEKsB+SgpgpgXIpLKZijyo+n1i0BaU9KBDH6nqV/KopAOi9QQs1iGPJjk6BHBufu1ik8d2sfB1msRHoQgfVUPYvbRXJ7o5Xg877+0R+qXXggV5oblpNzc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621446520; h=Content-Type:Content-Transfer-Encoding:Cc: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=FGZZlPwv+d3gDOF3OXABJO54lStwoRhMh3ULGo4CzDE=; b=kcpoQ/82p3nV6xGr9PZ9Ps+xJTTwYfwe5NHVOq4n5hyjumaTwG7RCXiMwo01zz4tp7ynnxts0OntBku0n/E8y7WmwTo2htEebRD4EixLv0saj3ZC67gbwmW1lL2GRwn+DGtV8dIGcUPZsy6F61h54+b7dWWe2fpBeE058BWnJiE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1621446520886811.0046399702478; Wed, 19 May 2021 10:48:40 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-139-Zi3UulWBNbmK6wtuIZHW4g-1; Wed, 19 May 2021 13:48:37 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B4A28015F8; Wed, 19 May 2021 17:48:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E6C760C03; Wed, 19 May 2021 17:48:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E159C180B463; Wed, 19 May 2021 17:48:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14JHfLw6011204 for ; Wed, 19 May 2021 13:41:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id E555B2077FC3; Wed, 19 May 2021 17:41:20 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E03522077FCA for ; Wed, 19 May 2021 17:41:17 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 485231825064 for ; Wed, 19 May 2021 17:41:17 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-539-LMe78TW-MdmgEneQ1RjCqA-1; Wed, 19 May 2021 13:41:14 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14JHXDv2012502; Wed, 19 May 2021 13:41:13 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 38n6ewhfdb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 13:41:12 -0400 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14JHXbuF013526; Wed, 19 May 2021 13:41:12 -0400 Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com with ESMTP id 38n6ewhfcj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 13:41:12 -0400 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 14JHcpNS004083; Wed, 19 May 2021 17:41:09 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma02fra.de.ibm.com with ESMTP id 38mceh8fed-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 May 2021 17:41:09 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14JHecKQ32047364 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 May 2021 17:40:38 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1E067A406A; Wed, 19 May 2021 17:41:06 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BA6F0A4069; Wed, 19 May 2021 17:41:05 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.40.136]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 19 May 2021 17:41:05 +0000 (GMT) X-MC-Unique: Zi3UulWBNbmK6wtuIZHW4g-1 X-MC-Unique: LMe78TW-MdmgEneQ1RjCqA-1 From: Boris Fiuczynski To: libvir-list@redhat.com, danielhb413@gmail.com Subject: [PATCH 1/4] conf: refactor launch security to allow more types Date: Wed, 19 May 2021 19:40:50 +0200 Message-Id: <20210519174053.10498-2-fiuczy@linux.ibm.com> In-Reply-To: <20210519174053.10498-1-fiuczy@linux.ibm.com> References: <20210519174053.10498-1-fiuczy@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 8L-vxMpAIdw10SQa7yIMI81MWrK40a0e X-Proofpoint-GUID: JOSBZBRHHxxBrZTO3wCNovde0NT_CkE_ X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-19_09:2021-05-19, 2021-05-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 spamscore=0 bulkscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 mlxscore=0 priorityscore=1501 clxscore=1015 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105190107 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: brijesh.singh@amd.com, eskultet@redhat.com, pasic@linux.ibm.com, mhartmay@linux.ibm.com, shalini@linux.ibm.com, bwalk@linux.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To allow other types of launch security the SEV type specific parameters like e.g. policy need to be optional and be separated from other new launch security types. A test is added to ensure the previously required and now optional launch security policy remains required when launch security type is SEV. Signed-off-by: Boris Fiuczynski Reviewed-by: Daniel Henrique Barboza --- docs/schemas/domaincommon.rng | 12 +- src/conf/domain_conf.c | 156 +++++++++++------- src/conf/domain_conf.h | 13 +- src/conf/virconftypes.h | 2 + src/qemu/qemu_cgroup.c | 4 +- src/qemu/qemu_command.c | 38 ++++- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_firmware.c | 4 +- src/qemu/qemu_namespace.c | 20 ++- src/qemu/qemu_process.c | 35 +++- src/qemu/qemu_validate.c | 22 ++- src/security/security_dac.c | 4 +- ...urity-sev-missing-policy.x86_64-2.12.0.err | 1 + .../launch-security-sev-missing-policy.xml | 34 ++++ tests/qemuxml2argvtest.c | 1 + 15 files changed, 253 insertions(+), 95 deletions(-) create mode 100644 tests/qemuxml2argvdata/launch-security-sev-missing-poli= cy.x86_64-2.12.0.err create mode 100644 tests/qemuxml2argvdata/launch-security-sev-missing-poli= cy.xml diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index a2e5c50c1d..3df13a0cf1 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -483,7 +483,9 @@ - sev + + sev + @@ -496,9 +498,11 @@ - - - + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b3ed3a9c5a..228de5d715 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3481,8 +3481,7 @@ virDomainResctrlDefFree(virDomainResctrlDef *resctrl) } =20 =20 -static void -virDomainSEVDefFree(virDomainSEVDef *def) +void virDomainSEVDefFree(virDomainSEVDef *def) { if (!def) return; @@ -3493,6 +3492,17 @@ virDomainSEVDefFree(virDomainSEVDef *def) g_free(def); } =20 +void virDomainSecDefFree(virDomainSecDef *def) +{ + if (!def) + return; + + virDomainSEVDefFree(def->sev); + + g_free(def); +} + + static void virDomainOSDefClear(virDomainOSDef *os) { @@ -3694,7 +3704,7 @@ void virDomainDefFree(virDomainDef *def) if (def->namespaceData && def->ns.free) (def->ns.free)(def->namespaceData); =20 - virDomainSEVDefFree(def->sev); + virDomainSecDefFree(def->sec); =20 xmlFreeNode(def->metadata); =20 @@ -14688,72 +14698,80 @@ virDomainSEVDefParseXML(xmlNodePtr sevNode, xmlXPathContextPtr ctxt) { VIR_XPATH_NODE_AUTORESTORE(ctxt) - virDomainSEVDef *def; + g_autoptr(virDomainSEVDef) sev =3D g_new0(virDomainSEVDef, 1); unsigned long policy; - g_autofree char *type =3D NULL; int rc =3D -1; =20 - def =3D g_new0(virDomainSEVDef, 1); - ctxt->node =3D sevNode; =20 - if (!(type =3D virXMLPropString(sevNode, "type"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing launch security type")); - goto error; - } - - def->sectype =3D virDomainLaunchSecurityTypeFromString(type); - switch ((virDomainLaunchSecurity) def->sectype) { - case VIR_DOMAIN_LAUNCH_SECURITY_SEV: - break; - case VIR_DOMAIN_LAUNCH_SECURITY_NONE: - case VIR_DOMAIN_LAUNCH_SECURITY_LAST: - default: - virReportError(VIR_ERR_XML_ERROR, - _("unsupported launch security type '%s'"), - type); - goto error; - } - if (virXPathULongHex("string(./policy)", ctxt, &policy) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", - _("failed to get launch security policy")); - goto error; + _("Failed to get launch security policy for " + "launch security type SEV")); + return NULL; } =20 /* the following attributes are platform dependent and if missing, we = can * autofill them from domain capabilities later */ - rc =3D virXPathUInt("string(./cbitpos)", ctxt, &def->cbitpos); + rc =3D virXPathUInt("string(./cbitpos)", ctxt, &sev->cbitpos); if (rc =3D=3D 0) { - def->haveCbitpos =3D true; + sev->haveCbitpos =3D true; } else if (rc =3D=3D -2) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Invalid format for launch security cbitpos")); - goto error; + return NULL; } =20 rc =3D virXPathUInt("string(./reducedPhysBits)", ctxt, - &def->reduced_phys_bits); + &sev->reduced_phys_bits); if (rc =3D=3D 0) { - def->haveReducedPhysBits =3D true; + sev->haveReducedPhysBits =3D true; } else if (rc =3D=3D -2) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Invalid format for launch security " "reduced-phys-bits")); - goto error; + return NULL; } =20 - def->policy =3D policy; - def->dh_cert =3D virXPathString("string(./dhCert)", ctxt); - def->session =3D virXPathString("string(./session)", ctxt); + sev->policy =3D policy; + sev->dh_cert =3D virXPathString("string(./dhCert)", ctxt); + sev->session =3D virXPathString("string(./session)", ctxt); =20 - return def; + return g_steal_pointer(&sev); +} =20 - error: - virDomainSEVDefFree(def); - return NULL; + +static virDomainSecDef * +virDomainSecDefParseXML(xmlNodePtr lsecNode, + xmlXPathContextPtr ctxt) +{ + g_autoptr(virDomainSecDef) sec =3D g_new0(virDomainSecDef, 1); + g_autofree char *type =3D NULL; + + if (!(type =3D virXMLPropString(lsecNode, "type"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing launch security type")); + return NULL; + } + + sec->sectype =3D virDomainLaunchSecurityTypeFromString(type); + switch ((virDomainLaunchSecurity) sec->sectype) { + case VIR_DOMAIN_LAUNCH_SECURITY_SEV: + sec->sev =3D virDomainSEVDefParseXML(lsecNode, ctxt); + if (!sec->sev) + return NULL; + break; + case VIR_DOMAIN_LAUNCH_SECURITY_NONE: + case VIR_DOMAIN_LAUNCH_SECURITY_LAST: + default: + virReportError(VIR_ERR_XML_ERROR, + _("unsupported launch security type '%s'"), + type); + return NULL; + } + + return g_steal_pointer(&sec); } =20 =20 @@ -20117,10 +20135,10 @@ virDomainDefParseXML(xmlDocPtr xml, ctxt->node =3D node; VIR_FREE(nodes); =20 - /* Check for SEV feature */ + /* Check for launch security e.g. SEV feature */ if ((node =3D virXPathNode("./launchSecurity", ctxt)) !=3D NULL) { - def->sev =3D virDomainSEVDefParseXML(node, ctxt); - if (!def->sev) + def->sec =3D virDomainSecDefParseXML(node, ctxt); + if (!def->sec) goto error; } =20 @@ -26845,30 +26863,44 @@ virDomainKeyWrapDefFormat(virBuffer *buf, virDoma= inKeyWrapDef *keywrap) =20 =20 static void -virDomainSEVDefFormat(virBuffer *buf, virDomainSEVDef *sev) +virDomainSecDefFormat(virBuffer *buf, virDomainSecDef *sec) { - if (!sev) + if (!sec) return; =20 - virBufferAsprintf(buf, "\n", - virDomainLaunchSecurityTypeToString(sev->sectype)); - virBufferAdjustIndent(buf, 2); + switch ((virDomainLaunchSecurity) sec->sectype) { + case VIR_DOMAIN_LAUNCH_SECURITY_SEV: { + virDomainSEVDef *sev =3D sec->sev; + if (!sev) + return; =20 - if (sev->haveCbitpos) - virBufferAsprintf(buf, "%d\n", sev->cbitpos); + virBufferAsprintf(buf, "\n", + virDomainLaunchSecurityTypeToString(sec->sectype= )); + virBufferAdjustIndent(buf, 2); =20 - if (sev->haveReducedPhysBits) - virBufferAsprintf(buf, "%d\n", - sev->reduced_phys_bits); - virBufferAsprintf(buf, "0x%04x\n", sev->policy); - if (sev->dh_cert) - virBufferEscapeString(buf, "%s\n", sev->dh_cert); + if (sev->haveCbitpos) + virBufferAsprintf(buf, "%d\n", sev->cbitpos= ); =20 - if (sev->session) - virBufferEscapeString(buf, "%s\n", sev->session= ); + if (sev->haveReducedPhysBits) + virBufferAsprintf(buf, "%d\= n", + sev->reduced_phys_bits); + virBufferAsprintf(buf, "0x%04x\n", sev->policy); + if (sev->dh_cert) + virBufferEscapeString(buf, "%s\n", sev->dh_ce= rt); + + if (sev->session) + virBufferEscapeString(buf, "%s\n", sev->ses= sion); + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + break; + } + + case VIR_DOMAIN_LAUNCH_SECURITY_NONE: + case VIR_DOMAIN_LAUNCH_SECURITY_LAST: + break; + } =20 - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); } =20 =20 @@ -28306,7 +28338,7 @@ virDomainDefFormatInternalSetRootName(virDomainDef = *def, if (def->keywrap) virDomainKeyWrapDefFormat(buf, def->keywrap); =20 - virDomainSEVDefFormat(buf, def->sev); + virDomainSecDefFormat(buf, def->sec); =20 if (def->namespaceData && def->ns.format) { if ((def->ns.format)(buf, def->namespaceData) < 0) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index cf8481f1f6..dd78f30ace 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2637,7 +2637,6 @@ typedef enum { =20 =20 struct _virDomainSEVDef { - int sectype; /* enum virDomainLaunchSecurity */ char *dh_cert; char *session; unsigned int policy; @@ -2647,6 +2646,10 @@ struct _virDomainSEVDef { unsigned int reduced_phys_bits; }; =20 +struct _virDomainSecDef { + int sectype; /* enum virDomainLaunchSecurity */ + virDomainSEVDef *sev; +}; =20 typedef enum { VIR_DOMAIN_IOMMU_MODEL_INTEL, @@ -2857,8 +2860,8 @@ struct _virDomainDef { =20 virDomainKeyWrapDef *keywrap; =20 - /* SEV-specific domain */ - virDomainSEVDef *sev; + /* launch security e.g. SEV */ + virDomainSecDef *sec; =20 /* Application-specific custom metadata */ xmlNodePtr metadata; @@ -3271,6 +3274,10 @@ void virDomainRedirdevDefFree(virDomainRedirdevDef *= def); void virDomainRedirFilterDefFree(virDomainRedirFilterDef *def); void virDomainShmemDefFree(virDomainShmemDef *def); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainShmemDef, virDomainShmemDefFree); +void virDomainSEVDefFree(virDomainSEVDef *def); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainSEVDef, virDomainSEVDefFree); +void virDomainSecDefFree(virDomainSecDef *def); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainSecDef, virDomainSecDefFree); void virDomainDeviceDefFree(virDomainDeviceDef *def); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainDeviceDef, virDomainDeviceDefFree); diff --git a/src/conf/virconftypes.h b/src/conf/virconftypes.h index ff5d8145c3..1459bea191 100644 --- a/src/conf/virconftypes.h +++ b/src/conf/virconftypes.h @@ -204,6 +204,8 @@ typedef struct _virDomainResourceDef virDomainResourceD= ef; =20 typedef struct _virDomainSEVDef virDomainSEVDef; =20 +typedef struct _virDomainSecDef virDomainSecDef; + typedef struct _virDomainShmemDef virDomainShmemDef; =20 typedef struct _virDomainSmartcardDef virDomainSmartcardDef; diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 0e8835fb86..72bff2cbed 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -854,7 +854,9 @@ qemuSetupDevicesCgroup(virDomainObj *vm) return -1; } =20 - if (vm->def->sev && qemuSetupSEVCgroup(vm) < 0) + if (vm->def->sec && + vm->def->sec->sectype =3D=3D VIR_DOMAIN_LAUNCH_SECURITY_SEV && + qemuSetupSEVCgroup(vm) < 0) return -1; =20 return 0; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d6c5308ef0..10dcf11d5b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6987,8 +6987,18 @@ qemuBuildMachineCommandLine(virCommand *cmd, if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_LOADPARM)) qemuAppendLoadparmMachineParm(&buf, def); =20 - if (def->sev) - virBufferAddLit(&buf, ",memory-encryption=3Dsev0"); + if (def->sec) { + switch ((virDomainLaunchSecurity) def->sec->sectype) { + case VIR_DOMAIN_LAUNCH_SECURITY_SEV: + virBufferAddLit(&buf, ",memory-encryption=3Dsev0"); + break; + case VIR_DOMAIN_LAUNCH_SECURITY_NONE: + break; + case VIR_DOMAIN_LAUNCH_SECURITY_LAST: + virReportEnumRangeError(virDomainLaunchSecurity, def->sec->sec= type); + return -1; + } + } =20 if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { if (priv->pflash0) @@ -9868,6 +9878,28 @@ qemuBuildSEVCommandLine(virDomainObj *vm, virCommand= *cmd, return 0; } =20 + +static int +qemuBuildSecCommandLine(virDomainObj *vm, virCommand *cmd, + virDomainSecDef *sec) +{ + if (!sec) + return 0; + + switch ((virDomainLaunchSecurity) sec->sectype) { + case VIR_DOMAIN_LAUNCH_SECURITY_SEV: + return qemuBuildSEVCommandLine(vm, cmd, sec->sev); + break; + case VIR_DOMAIN_LAUNCH_SECURITY_NONE: + break; + case VIR_DOMAIN_LAUNCH_SECURITY_LAST: + virReportEnumRangeError(virDomainLaunchSecurity, sec->sectype); + return -1; + } + + return 0; +} + static int qemuBuildVMCoreInfoCommandLine(virCommand *cmd, const virDomainDef *def) @@ -10567,7 +10599,7 @@ qemuBuildCommandLine(virQEMUDriver *driver, if (qemuBuildVMCoreInfoCommandLine(cmd, def) < 0) return NULL; =20 - if (qemuBuildSEVCommandLine(vm, cmd, def->sev) < 0) + if (qemuBuildSecCommandLine(vm, cmd, def->sec) < 0) return NULL; =20 if (snapshot) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c90d52edc0..c3deec439c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -19853,7 +19853,7 @@ qemuDomainGetLaunchSecurityInfo(virDomainPtr domain, if (virDomainGetLaunchSecurityInfoEnsureACL(domain->conn, vm->def) < 0) goto cleanup; =20 - if (vm->def->sev) { + if (vm->def->sec && vm->def->sec->sectype =3D=3D VIR_DOMAIN_LAUNCH_SEC= URITY_SEV) { if (qemuDomainGetSEVMeasurement(driver, vm, params, nparams, flags= ) < 0) goto cleanup; } diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index 2aeac635da..277ecc4b5b 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -1042,8 +1042,8 @@ qemuFirmwareMatchDomain(const virDomainDef *def, return false; } =20 - if (def->sev && - def->sev->sectype =3D=3D VIR_DOMAIN_LAUNCH_SECURITY_SEV && + if (def->sec && + def->sec->sectype =3D=3D VIR_DOMAIN_LAUNCH_SECURITY_SEV && !supportsSEV) { VIR_DEBUG("Domain requires SEV, firmware '%s' doesn't support it",= path); return false; diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index 6a97863d92..0dd1291c5d 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -594,16 +594,26 @@ static int qemuDomainSetupLaunchSecurity(virDomainObj *vm, GSList **paths) { - virDomainSEVDef *sev =3D vm->def->sev; + virDomainSecDef *sec =3D vm->def->sec; =20 - if (!sev || sev->sectype !=3D VIR_DOMAIN_LAUNCH_SECURITY_SEV) + if (!sec) return 0; =20 - VIR_DEBUG("Setting up launch security"); + switch ((virDomainLaunchSecurity) sec->sectype) { + case VIR_DOMAIN_LAUNCH_SECURITY_SEV: + VIR_DEBUG("Setting up launch security for SEV"); =20 - *paths =3D g_slist_prepend(*paths, g_strdup(QEMU_DEV_SEV)); + *paths =3D g_slist_prepend(*paths, g_strdup(QEMU_DEV_SEV)); + + VIR_DEBUG("Set up launch security for SEV"); + break; + case VIR_DOMAIN_LAUNCH_SECURITY_NONE: + break; + case VIR_DOMAIN_LAUNCH_SECURITY_LAST: + virReportEnumRangeError(virDomainLaunchSecurity, sec->sectype); + return -1; + } =20 - VIR_DEBUG("Set up launch security"); return 0; } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b69a9d1927..a7d88015ba 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6410,7 +6410,7 @@ qemuProcessUpdateSEVInfo(virDomainObj *vm) { qemuDomainObjPrivate *priv =3D vm->privateData; virQEMUCaps *qemuCaps =3D priv->qemuCaps; - virDomainSEVDef *sev =3D vm->def->sev; + virDomainSEVDef *sev =3D vm->def->sec->sev; virSEVCapability *sevCaps =3D NULL; =20 /* if platform specific info like 'cbitpos' and 'reducedPhysBits' have @@ -6566,7 +6566,7 @@ qemuProcessPrepareDomain(virQEMUDriver *driver, for (i =3D 0; i < vm->def->nshmems; i++) qemuDomainPrepareShmemChardev(vm->def->shmems[i]); =20 - if (vm->def->sev) { + if (vm->def->sec && vm->def->sec->sectype =3D=3D VIR_DOMAIN_LAUNCH_SEC= URITY_SEV) { VIR_DEBUG("Updating SEV platform info"); if (qemuProcessUpdateSEVInfo(vm) < 0) return -1; @@ -6602,12 +6602,13 @@ qemuProcessSEVCreateFile(virDomainObj *vm, =20 =20 static int -qemuProcessPrepareSEVGuestInput(virDomainObj *vm) +qemuProcessPrepareSEVGuestInput(virDomainObj *vm, + virDomainSecDef *sec) { - virDomainSEVDef *sev =3D vm->def->sev; + virDomainSEVDef *sev =3D sec->sev; =20 if (!sev) - return 0; + return -1; =20 VIR_DEBUG("Preparing SEV guest"); =20 @@ -6625,6 +6626,28 @@ qemuProcessPrepareSEVGuestInput(virDomainObj *vm) } =20 =20 +static int +qemuProcessPrepareLaunchSecurityGuestInput(virDomainObj *vm) +{ + virDomainSecDef *sec =3D vm->def->sec; + + if (!sec) + return 0; + + switch ((virDomainLaunchSecurity) sec->sectype) { + case VIR_DOMAIN_LAUNCH_SECURITY_SEV: + return qemuProcessPrepareSEVGuestInput(vm, sec); + case VIR_DOMAIN_LAUNCH_SECURITY_NONE: + break; + case VIR_DOMAIN_LAUNCH_SECURITY_LAST: + virReportEnumRangeError(virDomainLaunchSecurity, sec->sectype); + return -1; + } + + return 0; +} + + static int qemuProcessPrepareHostStorage(virQEMUDriver *driver, virDomainObj *vm, @@ -6804,7 +6827,7 @@ qemuProcessPrepareHost(virQEMUDriver *driver, if (qemuExtDevicesPrepareHost(driver, vm) < 0) return -1; =20 - if (qemuProcessPrepareSEVGuestInput(vm) < 0) + if (qemuProcessPrepareLaunchSecurityGuestInput(vm) < 0) return -1; =20 return 0; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 141203f979..78582a7c2a 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1214,12 +1214,22 @@ qemuValidateDomainDef(const virDomainDef *def, if (qemuValidateDomainDefPanic(def, qemuCaps) < 0) return -1; =20 - if (def->sev && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_SEV_GUEST)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("SEV launch security is not supported with " - "this QEMU binary")); - return -1; + if (def->sec) { + switch ((virDomainLaunchSecurity) def->sec->sectype) { + case VIR_DOMAIN_LAUNCH_SECURITY_SEV: + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SEV_GUEST)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("SEV launch security is not supported wit= h " + "this QEMU binary")); + return -1; + } + break; + case VIR_DOMAIN_LAUNCH_SECURITY_NONE: + break; + case VIR_DOMAIN_LAUNCH_SECURITY_LAST: + virReportEnumRangeError(virDomainLaunchSecurity, def->sec->sec= type); + return -1; + } } =20 if (def->naudios > 1 && diff --git a/src/security/security_dac.c b/src/security/security_dac.c index e973964735..289b614b73 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1980,7 +1980,7 @@ virSecurityDACRestoreAllLabel(virSecurityManager *mgr, rc =3D -1; } =20 - if (def->sev) { + if (def->sec && def->sec->sectype =3D=3D VIR_DOMAIN_LAUNCH_SECURITY_SE= V) { if (virSecurityDACRestoreSEVLabel(mgr, def) < 0) rc =3D -1; } @@ -2187,7 +2187,7 @@ virSecurityDACSetAllLabel(virSecurityManager *mgr, return -1; } =20 - if (def->sev) { + if (def->sec && def->sec->sectype =3D=3D VIR_DOMAIN_LAUNCH_SECURITY_SE= V) { if (virSecurityDACSetSEVLabel(mgr, def) < 0) return -1; } diff --git a/tests/qemuxml2argvdata/launch-security-sev-missing-policy.x86_= 64-2.12.0.err b/tests/qemuxml2argvdata/launch-security-sev-missing-policy.x= 86_64-2.12.0.err new file mode 100644 index 0000000000..63eaf64071 --- /dev/null +++ b/tests/qemuxml2argvdata/launch-security-sev-missing-policy.x86_64-2.12= .0.err @@ -0,0 +1 @@ +XML error: Failed to get launch security policy for launch security type S= EV diff --git a/tests/qemuxml2argvdata/launch-security-sev-missing-policy.xml = b/tests/qemuxml2argvdata/launch-security-sev-missing-policy.xml new file mode 100644 index 0000000000..5461b06c9d --- /dev/null +++ b/tests/qemuxml2argvdata/launch-security-sev-missing-policy.xml @@ -0,0 +1,34 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + + +
+ + + + + + + + + + AQAAAAAOAAAAQAAAAAOAAAAQAAAAAOAAAAQAAAAAOAAAAQAAAAAOAAA + IHAVENOIDEABUTJUSTPROVIDINGASTRING + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 25b0c81f21..594a01de45 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3496,6 +3496,7 @@ mymain(void) =20 DO_TEST_CAPS_VER("launch-security-sev", "2.12.0"); DO_TEST_CAPS_VER("launch-security-sev-missing-platform-info", "2.12.0"= ); + DO_TEST_CAPS_VER_PARSE_ERROR("launch-security-sev-missing-policy", "2.= 12.0"); =20 DO_TEST_CAPS_LATEST("vhost-user-fs-fd-memory"); DO_TEST_CAPS_LATEST("vhost-user-fs-hugepages"); --=20 2.30.2