Public bug reported:

[Impact]

LP: #2146560 introduced the OvmfPkg/FirmwareSecvarUpdater DXE driver in
edk2 (2025.11-3ubuntu7+ and 2026.05-2ubuntu1+) to automatically append
Microsoft's 2023 Secure Boot CAs onto existing legacy VMs whose NVRAM
only contained the 2011 CAs.

However, the pre-enrolled Secure Boot variable store templates built at
package build time via `enroll_vendor` in `debian/rules`
(`OVMF_VARS_4M.ms.fd`, `AAVMF_VARS.ms.fd`, and `OVMF.inteltdx.ms.fd`)
are generated with:

  virt-fw-vars --enroll-cert debian/PkKek-1-vendor.pem --set-dbx ...

In python3-virt-firmware, `--enroll-cert` defaults to `--microsoft-db all`,
which enrolls 6 of the 7 expected certificates (`db` = 6,133 bytes) but
omits two items that `FirmwareSecvarUpdater` expects:

1. `Microsoft Option ROM UEFI CA 2023` in `db`
   (`virt.firmware.efi.certs.MS_ROM_2023` / `ms-uefi-rom-2023.pem`,
   owner GUID `77fa9abd-0359-4d32-bd60-28f4e78f784b`, bringing `db` to
   7,636 bytes).
2. The `FirmwareSecvarUpdaterVersion` guard variable
   (GUID `a2f5da32-9e4c-4f6b-b3a1-7c8d5e6f0a1b`, attributes `NV|BS|RT` =
   `0x7`, 4-byte little-endian `UINT32` matching `SECVAR_UPDATER_VERSION`
   in `OvmfPkg/FirmwareSecvarUpdater/FirmwareSecvarUpdater.h`, currently 1).

Because both are absent from the shipped `*.ms.fd` templates, every
brand-new Secure Boot VM triggers `FirmwareSecvarUpdater` on its first
boot, entering `CustomMode`, rewriting all 7,636 bytes of `db`
byte-by-byte in SMM, and writing `FirmwareSecvarUpdaterVersion`:

- Every new Secure Boot VM incurs ~0.5–1.1s of unnecessary SMM flash
  writes on first boot.
- If QEMU is force-stopped (e.g. `lxc stop -f`, crash, or timeout)
  during that first-boot SMM write window (~0.4–1.2s), `db` can be left
  in `VAR_IN_DELETED_TRANSITION` (`0x3e`), triggering an ~80–150s SMM
  `FtwReclaim` delay on the next boot (reproduced at 83.5s on KVM with
  `ovmf 2025.11-3ubuntu7.4`).

Fix:
- In `debian/rules`, update `enroll_vendor` and the `%.ms.fd` pattern
  rule to also pass `--add-db 77fa9abd-0359-4d32-bd60-28f4e78f784b` with
  `virt.firmware.efi.certs.MS_ROM_2023` and `--set-json` with a
  generated JSON file encoding `FirmwareSecvarUpdaterVersion` read
  dynamically from `SECVAR_UPDATER_VERSION` in
  `OvmfPkg/FirmwareSecvarUpdater/FirmwareSecvarUpdater.h` (so future
  version bumps cannot drift).
- In `debian/tests/secvar_update.py`:
  - Add `test_ovmf_ms_template_preenrolled` and
    `test_aavmf_ms_template_preenrolled` asserting that freshly built
    `OVMF_VARS_4M.ms.fd` / `AAVMF_VARS.ms.fd` templates already contain
    all 7 Microsoft CAs and `FirmwareSecvarUpdaterVersion`, and that
    booting QEMU once produces zero NVRAM rewrites to `KEK`, `db`, or
    `FirmwareSecvarUpdaterVersion`.
  - Update `strip_2023_certs()` / `make_2011_only_vars()` to also strip
    `FirmwareSecvarUpdaterVersion` when synthesizing a legacy 2011-only
    varstore so the existing upgrade tests still exercise
    `ApplyUpdateRules()`.

[Test Plan]

1. Inspect the built `.ms.fd` templates (`OVMF_VARS_4M.ms.fd`,
   `AAVMF_VARS.ms.fd`, `OVMF.inteltdx.ms.fd`) with `virt-fw-vars -p -v`:
   - `db` is 7,636 bytes and contains all 5 Microsoft `db` CAs including
     `Microsoft Option ROM UEFI CA 2023` (all with owner GUID
     `77fa9abd-0359-4d32-bd60-28f4e78f784b`).
   - `KEK` is 3,936 bytes (vendor PK/KEK + 2011 + 2023 KEK CAs).
   - `FirmwareSecvarUpdaterVersion` (`a2f5da32-9e4c-4f6b-b3a1-7c8d5e6f0a1b`)
     is present with `attr=0x7` and `dword: 0x00000001`.
2. Run `PYTHONPATH=./debian/python python3 debian/tests/secvar_update.py`
   on `amd64` and `arm64`:
   - `test_*_ms_template_preenrolled` passes, confirming zero NVRAM
     rewrites to `KEK`, `db`, or `FirmwareSecvarUpdaterVersion` on first
     boot.
   - `test_*_secvar_update_appends_2023_certs` and
     `test_ovmf_secvar_update_version_guard` continue to pass, confirming
     legacy 2011-only VMs are still upgraded and the version guard still
     prevents re-running.
3. Boot QEMU (`q35,smm=on,accel=kvm`) with `OVMF_CODE_4M.ms.fd` and a
   fresh copy of `OVMF_VARS_4M.ms.fd` and send `SIGKILL` at 0.4s, 0.8s,
   and 1.2s into first boot; confirm `KEK`, `db`, and
   `FirmwareSecvarUpdaterVersion` remain untouched in state `0x3f` with
   zero `0x3e` (`VAR_IN_DELETED_TRANSITION`) records.

[Where problems could occur]

- Existing VMs already have their own per-VM NVRAM copies and are
  unaffected by template changes; legacy 2011-only VMs still lack
  `FirmwareSecvarUpdaterVersion` and will still be upgraded on boot by
  `FirmwareSecvarUpdater`.
- If a future upload bumps `SECVAR_UPDATER_VERSION` in
  `FirmwareSecvarUpdater.h` to add new certificates without also adding
  those certificates to `enroll_vendor` in `debian/rules`, new templates
  would advertise the higher version while missing the newly added
  certificates. Any such future update should add the new certs to
  `enroll_vendor` and `EXPECTED_CERTS` in `secvar_update.py` so
  `test_*_ms_template_preenrolled` catches any mismatch at build/test
  time.
- `debian/rules` reads `virt.firmware.efi.certs.MS_ROM_2023` from
  `python3-virt-firmware` (already in `Build-Depends`, ships
  `ms-uefi-rom-2023.pem` in Resolute 25.12-1 and later). If
  `python3-virt-firmware` ever renames that internal attribute or changes
  its `certs` module layout, the build will fail loudly rather than
  silently producing incomplete templates.

** Affects: edk2 (Ubuntu)
     Importance: Undecided
         Status: New

** Merge proposal linked:
   
https://code.launchpad.net/~sdeziel/ubuntu/+source/edk2/+git/edk2/+merge/515666

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2183410

Title:
  Pre-enroll Microsoft Option ROM UEFI CA 2023 and
  FirmwareSecvarUpdaterVersion in *.ms.fd templates

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/edk2/+bug/2183410/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to