Skip to contentSkip to conversation

hw/uefi: improve default config security

PATCH New Gerd Hoffmann 1 participant 3 messages Sep 4

lore
Share & tools
lore
#0 lore raw

cover hw/uefi: improve default config security

Gerd Hoffmann (2):
hw/uefi: add require-self-signed-pk config option hw/uefi: improve default config security

 include/hw/uefi/var-service.h |  1 +
 hw/uefi/var-service-auth.c    | 25 +++++++++++++++----------
 hw/uefi/var-service-sysbus.c  |  4 +++-
 3 files changed, 19 insertions(+), 11 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/2 hw/uefi: add require-self-signed-pk config option

Traditional edk2 behavior is to require a self-signed platform key when enrolling secure boot certificates in setup mode. In 2023 a config option has been added (PcdRequireSelfSignedPk) which allows to relax that requirement, see edk2 commit 566cdfc675fa ("SecurityPkg: limit verification of enrolled PK in setup mode").

This patch adds a similar config option to the qemu uefi variable driver.

No functional change, the default value for the new config option maintains existing behavior.

---
 include/hw/uefi/var-service.h |  1 +
 hw/uefi/var-service-auth.c    | 25 +++++++++++++++----------
 hw/uefi/var-service-sysbus.c  |  2 ++
 3 files changed, 18 insertions(+), 10 deletions(-)
include/hw/uefi/var-service.h +1 -0
index 7d84025cd58d..7f74b4423381 100644
@@ -76,6 +76,7 @@ struct uefi_vars_state {
     int                               jsonfd;
     bool                              force_secure_boot;
     bool                              disable_custom_mode;
+    bool                              require_self_signed_pk;
     bool                              use_pio;
 
     /* request + reply capture */
hw/uefi/var-service-auth.c +15 -10
index 899444af12df..21fc50f904d5 100644
@@ -201,16 +201,21 @@ static efi_status uefi_vars_check_auth_2_sb(uefi_vars_state *uv,
 
     siglist = uefi_vars_find_siglist(uv, var);
     if (!siglist && setup_mode_is_active(uv) && uefi_vars_is_sb_pk(var)) {
-        /* check PK is self-signed */
-        uefi_variable tmp = {
-            .guid       = EfiGlobalVariable,
-            .name       = (uint16_t *)name_pk,
-            .name_size  = sizeof(name_pk),
-            .attributes = sigdb_attrs,
-            .data       = data + data_offset,
-            .data_size  = va->data_size - data_offset,
-        };
-        return uefi_vars_check_pkcs7_2(&tmp, NULL, NULL, va, data);
+        /* edk2 config option is PcdRequireSelfSignedPk */
+        if (uv->require_self_signed_pk) {
+            /* check PK is self-signed */
+            uefi_variable tmp = {
+                .guid       = EfiGlobalVariable,
+                .name       = (uint16_t *)name_pk,
+                .name_size  = sizeof(name_pk),
+                .attributes = sigdb_attrs,
+                .data       = data + data_offset,
+                .data_size  = va->data_size - data_offset,
+            };
+            return uefi_vars_check_pkcs7_2(&tmp, NULL, NULL, va, data);
+        } else {
+            return true;
+        }
     }
 
     return uefi_vars_check_pkcs7_2(siglist, NULL, NULL, va, data);
hw/uefi/var-service-sysbus.c +2 -0
index 97a96cae6a2b..c4acdea275ad 100644
@@ -38,6 +38,8 @@ static const Property uefi_vars_sysbus_properties[] = {
                      state.force_secure_boot, false),
     DEFINE_PROP_BOOL("disable-custom-mode", uefi_vars_sysbus_state,
                      state.disable_custom_mode, false),
+    DEFINE_PROP_BOOL("require-self-signed-pk", uefi_vars_sysbus_state,
+                     state.require_self_signed_pk, true),
     DEFINE_PROP_BOOL("use-pio", uefi_vars_sysbus_state,
                      state.use_pio, false),
 };
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/2 hw/uefi: improve default config security

In reply to Gerd Hoffmann

Recent UEFI spec versions do not require a self-signed PK any more. There is no good reason to stick to this requirement, but there is one reason to remove it: It is not needed to enable CustomMode then to enroll secure boot keys which are not self-signed.

This commit changes the uefi-vars default configuration to remove the self signed platform key requirement and to disable CustomMode.

Little background on CustomMode:

This is a special edk2 mode which allows to freely update secure boot variables. This is used by the firmware setup utility to allow the user change the secure boot certificates. The EnrollDefaultKeys.efi utility used to depend on CustomMode too.

Typically enabling CustomMode requires the user being physically present. Implementing such a check in a sensible way for a virtual machine is not really possible though. So OVMF doesn't do that and CustomMode can be enabled without that physical presence check. Therefore disabling CustomMode (by the qemu variable service blocking updates of the EFI variable with EFI_WRITE_PROTECTED) is a nice security improvement for secure boot support in virtual machines.

User-visible change: Updating secure boot configuration via firmware setup utility does not work by default. Setting the "disable-custom-mode=off" property will re-enable this if needed. Alternatively the variable store can be prepared on the host machine instead of doing it inside the guest.

Related edk2 commits:
- 3c01a11daae2 ("OvmfPkg: set PcdRequireSelfSignedPk to FALSE").
- 0a7ed7ed3457 ("OvmfPkg/EnrollDefaultKeys: do not require CustomMode")

---
 hw/uefi/var-service-sysbus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/uefi/var-service-sysbus.c +2 -2
index c4acdea275ad..e5e0441e16f7 100644
@@ -37,9 +37,9 @@ static const Property uefi_vars_sysbus_properties[] = {
     DEFINE_PROP_BOOL("force-secure-boot", uefi_vars_sysbus_state,
                      state.force_secure_boot, false),
     DEFINE_PROP_BOOL("disable-custom-mode", uefi_vars_sysbus_state,
-                     state.disable_custom_mode, false),
+                     state.disable_custom_mode, true),
     DEFINE_PROP_BOOL("require-self-signed-pk", uefi_vars_sysbus_state,
-                     state.require_self_signed_pk, true),
+                     state.require_self_signed_pk, false),
     DEFINE_PROP_BOOL("use-pio", uefi_vars_sysbus_state,
                      state.use_pio, false),
 };
Signature · 1 line
2.55.0