From nobody Mon Feb 9 17:34:52 2026 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=1656000929; cv=none; d=zohomail.com; s=zohoarc; b=QbFiDTVbxrl9BiG220TgAR/oBIjcSdpRvPE1f31RqTDxAWESfTURZQ7F48V1dKqH/FD4cP671ZSj7vYxJpuO2wleegsd8k0eljxvgfEdR2eMAGY+tk/VzIwmozD+fd84V5XgjGEnzuR5Cm2hqfDEMO1IycDpAMz3pXObn4eVP94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656000929; 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=ROtRv84o5AOJnUN6Z4BRbj30uptiG7KyZD3T9G/zYQA=; b=e39IIDhE6uuOy7TM0NSmT3vA6vWJmjtj3xJHhLItjUMwe/4fYTTPHQ9iOtZ/hy3vQRvVWCEpGY3Y87JMQUS+w8OnrfYg37rE4lwlNnkQ77HD928REWMEXeBuVL0DPSfP7AUKRos3CoBoaWTx4vPkrvG1VGd7t7Ek4S9t5L/Pp0o= 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 1656000929076327.6328436593934; Thu, 23 Jun 2022 09:15:29 -0700 (PDT) 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-408-ENa0XYZ4N-inKjYOs1do4g-1; Thu, 23 Jun 2022 12:15:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 36352905C6D; Thu, 23 Jun 2022 16:15:04 +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 992CE18EAB; Thu, 23 Jun 2022 16:15: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 65C12194B95B; Thu, 23 Jun 2022 16:15:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 17BC9194B95F for ; Thu, 23 Jun 2022 16:15:00 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EE5A91121330; Thu, 23 Jun 2022 16:14:59 +0000 (UTC) Received: from harajuku.homenet.telecomitalia.it (unknown [10.40.194.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 79DA71121314 for ; Thu, 23 Jun 2022 16:14:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656000928; 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=ROtRv84o5AOJnUN6Z4BRbj30uptiG7KyZD3T9G/zYQA=; b=TAfpPi1++dMqmSp8DDjXJUOsoMRfATYimqNUeP73nIEyPe44IMPL/ilwD9VEKSr3aaRLNg hIKORB+TGHdoq5AgZlZq7RJ9RX7gYFOC5W/zxIGojsJAhKbSWsaJIoGgMT0gR71Yz1zHw6 uUMimmCdMl+nhx/azwg2zHeFFxKCE7Q= X-MC-Unique: ENa0XYZ4N-inKjYOs1do4g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 22/28] conf: Validate firmware configuration more thoroughly Date: Thu, 23 Jun 2022 18:14:34 +0200 Message-Id: <20220623161440.61653-23-abologna@redhat.com> In-Reply-To: <20220623161440.61653-1-abologna@redhat.com> References: <20220623161440.61653-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 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 2.79 on 10.11.54.5 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 X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1656000929776100002 Content-Type: text/plain; charset="utf-8" Generally speaking, when firmware autoselection is in use we don't want any information to be provided manually. There are two exceptions: * we still want the path to the NVRAM file to be customizable; * using was how you would ask for a firmware that implements the Secure Boot feature in the original approach to firmware autoselection, so we want to keep that working. Anything else should result in a descriptive error. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/327 Signed-off-by: Andrea Bolognani --- src/conf/domain_validate.c | 48 +++++++++++++++++++ ...firmware-auto-bios-nvram.x86_64-latest.err | 1 + .../firmware-auto-bios-nvram.xml | 18 +++++++ ...auto-efi-loader-insecure.x86_64-latest.err | 1 + .../firmware-auto-efi-loader-insecure.xml | 18 +++++++ ...are-auto-efi-loader-path.x86_64-latest.err | 1 + .../firmware-auto-efi-loader-path.xml | 18 +++++++ tests/qemuxml2argvtest.c | 3 ++ 8 files changed, 108 insertions(+) create mode 100644 tests/qemuxml2argvdata/firmware-auto-bios-nvram.x86_64-= latest.err create mode 100644 tests/qemuxml2argvdata/firmware-auto-bios-nvram.xml create mode 100644 tests/qemuxml2argvdata/firmware-auto-efi-loader-insecur= e.x86_64-latest.err create mode 100644 tests/qemuxml2argvdata/firmware-auto-efi-loader-insecur= e.xml create mode 100644 tests/qemuxml2argvdata/firmware-auto-efi-loader-path.x8= 6_64-latest.err create mode 100644 tests/qemuxml2argvdata/firmware-auto-efi-loader-path.xml diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 1f6c32a816..87fdb677d1 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -1606,6 +1606,54 @@ virDomainDefOSValidate(const virDomainDef *def, _("firmware auto selection not implemented for = this driver")); return -1; } + + if (!loader) + return 0; + + if (loader->readonly) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("loader attribute 'readonly' cannot be specif= ied " + "when firmware autoselection is enabled")); + return -1; + } + if (loader->type) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("loader attribute 'type' cannot be specified " + "when firmware autoselection is enabled")); + return -1; + } + if (loader->path) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("loader path cannot be specified " + "when firmware autoselection is enabled")); + return -1; + } + if (loader->nvramTemplate) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("nvram attribute 'template' cannot be specifi= ed " + "when firmware autoselection is enabled")); + return -1; + } + + /* We need to accept 'yes' here because the initial implementation + * of firmware autoselection used it as a way to request a firmware + * with Secure Boot support, so the error message is technically + * incorrect; however, we want to discourage people from using this + * attribute at all, so it's fine to be a bit more aggressive than + * it would be strictly required :) */ + if (loader->secure =3D=3D VIR_TRISTATE_BOOL_NO) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("loader attribute 'secure' cannot be specifie= d " + "when firmware autoselection is enabled")); + return -1; + } + + if (loader->nvram && def->os.firmware !=3D VIR_DOMAIN_OS_DEF_FIRMW= ARE_EFI) { + virReportError(VIR_ERR_XML_DETAIL, + _("firmware type '%s' does not support nvram"), + virDomainOsDefFirmwareTypeToString(def->os.firm= ware)); + return -1; + } } else { if (!loader) return 0; diff --git a/tests/qemuxml2argvdata/firmware-auto-bios-nvram.x86_64-latest.= err b/tests/qemuxml2argvdata/firmware-auto-bios-nvram.x86_64-latest.err new file mode 100644 index 0000000000..772beb49e2 --- /dev/null +++ b/tests/qemuxml2argvdata/firmware-auto-bios-nvram.x86_64-latest.err @@ -0,0 +1 @@ +firmware type 'bios' does not support nvram diff --git a/tests/qemuxml2argvdata/firmware-auto-bios-nvram.xml b/tests/qe= muxml2argvdata/firmware-auto-bios-nvram.xml new file mode 100644 index 0000000000..6dad1e1f7f --- /dev/null +++ b/tests/qemuxml2argvdata/firmware-auto-bios-nvram.xml @@ -0,0 +1,18 @@ + + fedora + 63840878-0deb-4095-97e6-fc444d9bc9fa + 8192 + 1 + + hvm + /path/to/fedora_VARS.fd + + + + + + /usr/bin/qemu-system-x86_64 + + + + diff --git a/tests/qemuxml2argvdata/firmware-auto-efi-loader-insecure.x86_6= 4-latest.err b/tests/qemuxml2argvdata/firmware-auto-efi-loader-insecure.x86= _64-latest.err new file mode 100644 index 0000000000..564f0e6918 --- /dev/null +++ b/tests/qemuxml2argvdata/firmware-auto-efi-loader-insecure.x86_64-lates= t.err @@ -0,0 +1 @@ +loader attribute 'secure' cannot be specified when firmware autoselection = is enabled diff --git a/tests/qemuxml2argvdata/firmware-auto-efi-loader-insecure.xml b= /tests/qemuxml2argvdata/firmware-auto-efi-loader-insecure.xml new file mode 100644 index 0000000000..33bd7b0ac1 --- /dev/null +++ b/tests/qemuxml2argvdata/firmware-auto-efi-loader-insecure.xml @@ -0,0 +1,18 @@ + + fedora + 63840878-0deb-4095-97e6-fc444d9bc9fa + 8192 + 1 + + hvm + + + + + + + /usr/bin/qemu-system-x86_64 + + + + diff --git a/tests/qemuxml2argvdata/firmware-auto-efi-loader-path.x86_64-la= test.err b/tests/qemuxml2argvdata/firmware-auto-efi-loader-path.x86_64-late= st.err new file mode 100644 index 0000000000..e551fafd03 --- /dev/null +++ b/tests/qemuxml2argvdata/firmware-auto-efi-loader-path.x86_64-latest.err @@ -0,0 +1 @@ +loader attribute 'type' cannot be specified when firmware autoselection is= enabled diff --git a/tests/qemuxml2argvdata/firmware-auto-efi-loader-path.xml b/tes= ts/qemuxml2argvdata/firmware-auto-efi-loader-path.xml new file mode 100644 index 0000000000..a40f5e730c --- /dev/null +++ b/tests/qemuxml2argvdata/firmware-auto-efi-loader-path.xml @@ -0,0 +1,18 @@ + + fedora + 63840878-0deb-4095-97e6-fc444d9bc9fa + 8192 + 1 + + hvm + /path/to/OVMF_CODE.fd + + + + + + /usr/bin/qemu-system-x86_64 + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index b01ad8d4e9..473e00ffa7 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1217,9 +1217,12 @@ mymain(void) DO_TEST_NOCAPS("firmware-manual-noefi-noacpi-q35"); =20 DO_TEST_CAPS_LATEST("firmware-auto-bios"); + DO_TEST_CAPS_LATEST_PARSE_ERROR("firmware-auto-bios-nvram"); DO_TEST_CAPS_LATEST("firmware-auto-efi"); DO_TEST_CAPS_LATEST("firmware-auto-efi-nvram"); DO_TEST_CAPS_LATEST("firmware-auto-efi-loader-secure"); + DO_TEST_CAPS_LATEST_PARSE_ERROR("firmware-auto-efi-loader-insecure"); + DO_TEST_CAPS_LATEST_PARSE_ERROR("firmware-auto-efi-loader-path"); DO_TEST_CAPS_LATEST("firmware-auto-efi-secboot"); DO_TEST_CAPS_LATEST("firmware-auto-efi-no-secboot"); DO_TEST_CAPS_LATEST("firmware-auto-efi-enrolled-keys"); --=20 2.35.3