From nobody Sun Feb 8 15:46:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1616070517; cv=none; d=zohomail.com; s=zohoarc; b=fs6N662PNnzGNKK60AUwbcIHbEBMxPvwEiTT0sIhWDoOEfv7XITisrb7yAidKYgt5iYIXxwsA66g5GY4eJv3utY8fFwhsmI4w4iEy1RBKG7mXm0PnuRtR4CGbtKEYz9Ky3DradWwWq0rrO0H0VAcAgjqcnia3p66iXfSaB2K5Ko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616070517; 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=2jOtOjnb8+ckPJ6bxBzq58MYR3EcOBVb4K77DXBO4v8=; b=M7VcYhUupMobNSURY4Sj8Z8VL6wxhKIZATMCvfQHpwPhbzivifaiVnaXc2hkXGSjPJKiYSrzG9hLGnAkub2MCVcVFsxPRVmtGm+6zKt61MPIT6j4GrynyYu7oL7KFDACHcMONexHVmI7/VoVKkmrYmGjFEklqHCZhe9/L1OtZCk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1616070517690669.6104670473595; Thu, 18 Mar 2021 05:28:37 -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-490-Tppk9uuGPZ-wjykmgZHOeQ-1; Thu, 18 Mar 2021 08:28:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2682D1927807; Thu, 18 Mar 2021 12:28:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E756A5D723; Thu, 18 Mar 2021 12:28:28 +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 8D1E34A7CB; Thu, 18 Mar 2021 12:28:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 12ICRC5E024781 for ; Thu, 18 Mar 2021 08:27:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1F53818813; Thu, 18 Mar 2021 12:27:12 +0000 (UTC) Received: from antique-work.lan (unknown [10.40.192.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E7805C582 for ; Thu, 18 Mar 2021 12:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616070516; 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=2jOtOjnb8+ckPJ6bxBzq58MYR3EcOBVb4K77DXBO4v8=; b=KFfD1rgqBtEdUhThh65ierA0FK0ZGL3rlSMRf1BcR2YLrxoie4TBFJjbv9dh5MR4cwwoYS 8OOIYQ142TQgWNn/Ce7iMqoh1wm5s9b7qB3EAxed/qqF8cBZm6iAhJ3OlhwvHhNIkaotSv HbwZ4IXhFwRMcuWtHp/oYyDLbvSrtpI= X-MC-Unique: Tppk9uuGPZ-wjykmgZHOeQ-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 9/9] qemu: implement support for firmware auto-selection feature filtering Date: Thu, 18 Mar 2021 13:26:46 +0100 Message-Id: <31c20ee58e900499a4e3c6377edd903dfd6149f0.1616070296.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.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.15 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/qemu/qemu_firmware.c | 40 +++++++++++++++ ...re-efi-no-enrolled-keys.x86_64-latest.args | 49 ++++++++++++++++++ .../os-firmware-efi-no-enrolled-keys.xml | 25 ++++++++++ tests/qemuxml2argvtest.c | 1 + ...are-efi-no-enrolled-keys.x86_64-latest.xml | 50 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 6 files changed, 166 insertions(+) create mode 100644 tests/qemuxml2argvdata/os-firmware-efi-no-enrolled-keys= .x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/os-firmware-efi-no-enrolled-keys= .xml create mode 100644 tests/qemuxml2xmloutdata/os-firmware-efi-no-enrolled-ke= ys.x86_64-latest.xml diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index d3198e2d45..f6f371f51f 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -930,6 +930,10 @@ qemuFirmwareMatchDomain(const virDomainDef *def, bool supportsS4 =3D false; bool requiresSMM =3D false; bool supportsSEV =3D false; + bool supportsSecureBoot =3D false; + bool hasEnrolledKeys =3D false; + int reqSecureBoot; + int reqEnrolledKeys; =20 want =3D qemuFirmwareOSInterfaceTypeFromOsDefFirmware(def->os.firmware= ); =20 @@ -979,7 +983,13 @@ qemuFirmwareMatchDomain(const virDomainDef *def, break; =20 case QEMU_FIRMWARE_FEATURE_SECURE_BOOT: + supportsSecureBoot =3D true; + break; + case QEMU_FIRMWARE_FEATURE_ENROLLED_KEYS: + hasEnrolledKeys =3D true; + break; + case QEMU_FIRMWARE_FEATURE_VERBOSE_DYNAMIC: case QEMU_FIRMWARE_FEATURE_VERBOSE_STATIC: case QEMU_FIRMWARE_FEATURE_NONE: @@ -1000,6 +1010,36 @@ qemuFirmwareMatchDomain(const virDomainDef *def, return false; } =20 + if (def->os.firmwareFeatures) { + reqSecureBoot =3D def->os.firmwareFeatures[VIR_DOMAIN_OS_DEF_FIRMW= ARE_FEATURE_SECURE_BOOT]; + if (reqSecureBoot !=3D VIR_TRISTATE_BOOL_ABSENT) { + if (reqSecureBoot =3D=3D VIR_TRISTATE_BOOL_YES && !supportsSec= ureBoot) { + VIR_DEBUG("User requested Secure Boot, firmware '%s' doesn= 't support it", + path); + return false; + } + + if (reqSecureBoot =3D=3D VIR_TRISTATE_BOOL_NO && supportsSecur= eBoot) { + VIR_DEBUG("User refused Secure Boot, firmware '%s' support= s it", path); + return false; + } + } + + reqEnrolledKeys =3D def->os.firmwareFeatures[VIR_DOMAIN_OS_DEF_FIR= MWARE_FEATURE_ENROLLED_KEYS]; + if (reqEnrolledKeys !=3D VIR_TRISTATE_BOOL_ABSENT) { + if (reqEnrolledKeys =3D=3D VIR_TRISTATE_BOOL_YES && !hasEnroll= edKeys) { + VIR_DEBUG("User requested Enrolled keys, firmware '%s' doe= sn't support it", + path); + return false; + } + + if (reqEnrolledKeys =3D=3D VIR_TRISTATE_BOOL_NO && hasEnrolled= Keys) { + VIR_DEBUG("User refused Enrolled keys, firmware '%s' suppo= rts it", path); + return false; + } + } + } + if (def->os.loader && def->os.loader->secure =3D=3D VIR_TRISTATE_BOOL_YES && !requiresSMM) { diff --git a/tests/qemuxml2argvdata/os-firmware-efi-no-enrolled-keys.x86_64= -latest.args b/tests/qemuxml2argvdata/os-firmware-efi-no-enrolled-keys.x86_= 64-latest.args new file mode 100644 index 0000000000..561a905e78 --- /dev/null +++ b/tests/qemuxml2argvdata/os-firmware-efi-no-enrolled-keys.x86_64-latest= .args @@ -0,0 +1,49 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-fedora \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-fedora/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-fedora/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/domain--1-fedora/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3Dfedora,debug-threads=3Don \ +-S \ +-object secret,id=3DmasterKey0,format=3Draw,\ +file=3D/tmp/lib/domain--1-fedora/master-key.aes \ +-blockdev '{"driver":"file","filename":"/usr/share/OVMF/OVMF_CODE.fd",\ +"node-name":"libvirt-pflash0-storage","auto-read-only":true,\ +"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-pflash0-format","read-only":true,\ +"driver":"raw","file":"libvirt-pflash0-storage"}' \ +-blockdev '{"driver":"file",\ +"filename":"/var/lib/libvirt/qemu/nvram/fedora_VARS.fd",\ +"node-name":"libvirt-pflash1-storage","auto-read-only":true,\ +"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-pflash1-format","read-only":false,\ +"driver":"raw","file":"libvirt-pflash1-storage"}' \ +-machine pc-q35-4.0,accel=3Dkvm,usb=3Doff,dump-guest-core=3Doff,\ +pflash0=3Dlibvirt-pflash0-format,pflash1=3Dlibvirt-pflash1-format,\ +memory-backend=3Dpc.ram \ +-cpu qemu64 \ +-m 8 \ +-object memory-backend-ram,id=3Dpc.ram,size=3D8388608 \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid 63840878-0deb-4095-97e6-fc444d9bc9fa \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-boot strict=3Don \ +-device pcie-root-port,port=3D0x8,chassis=3D1,id=3Dpci.1,bus=3Dpcie.0,mult= ifunction=3Don,\ +addr=3D0x1 \ +-device pcie-root-port,port=3D0x9,chassis=3D2,id=3Dpci.2,bus=3Dpcie.0,addr= =3D0x1.0x1 \ +-device qemu-xhci,id=3Dusb,bus=3Dpci.1,addr=3D0x0 \ +-audiodev id=3Daudio1,driver=3Dnone \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ +resourcecontrol=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/os-firmware-efi-no-enrolled-keys.xml b/= tests/qemuxml2argvdata/os-firmware-efi-no-enrolled-keys.xml new file mode 100644 index 0000000000..6c0b323fd4 --- /dev/null +++ b/tests/qemuxml2argvdata/os-firmware-efi-no-enrolled-keys.xml @@ -0,0 +1,25 @@ + + fedora + 63840878-0deb-4095-97e6-fc444d9bc9fa + 8192 + 8192 + 1 + + + + + hvm + + + + + + + + /usr/bin/qemu-system-x86_64 + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 2b32b7f303..44c2a316b0 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3549,6 +3549,7 @@ mymain(void) DO_TEST_CAPS_LATEST("os-firmware-bios"); DO_TEST_CAPS_LATEST("os-firmware-efi"); DO_TEST_CAPS_LATEST("os-firmware-efi-secboot"); + DO_TEST_CAPS_LATEST("os-firmware-efi-no-enrolled-keys"); DO_TEST_CAPS_LATEST_PARSE_ERROR("os-firmware-invalid-type"); DO_TEST_CAPS_ARCH_LATEST("aarch64-os-firmware-efi", "aarch64"); =20 diff --git a/tests/qemuxml2xmloutdata/os-firmware-efi-no-enrolled-keys.x86_= 64-latest.xml b/tests/qemuxml2xmloutdata/os-firmware-efi-no-enrolled-keys.x= 86_64-latest.xml new file mode 100644 index 0000000000..3dbfbf0082 --- /dev/null +++ b/tests/qemuxml2xmloutdata/os-firmware-efi-no-enrolled-keys.x86_64-late= st.xml @@ -0,0 +1,50 @@ + + fedora + 63840878-0deb-4095-97e6-fc444d9bc9fa + 8192 + 8192 + 1 + + hvm + + + + + + + + + + + + qemu64 + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + +
+ + +
+ + + + +
+ + + + +
+ + + +