Skip to content

Commit bcdcbdb

Browse files
committed
Add UEFI variable append tests
Fallout from the varstored update. At the moment, test the following scenarios: * From the varstored defaults, append MS dbx and verify VM boots * From the varstored 1.2.0-3.1 defaults, append MS dbx and verify VM boots (which implies not having the oversized variable append bug) Signed-off-by: Tu Dinh <ngoc-tu.dinh@vates.tech>
1 parent 71f6003 commit bcdcbdb

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed
23.5 KB
Binary file not shown.

contrib/varstored/dbx_poison.auth

38.8 KB
Binary file not shown.

lib/efi.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ def db_uefi_2023(self):
7272
def db_oprom_2023(self):
7373
return str(self._prefix / "secureboot_objects/DB/Certificates/microsoft option rom uefi ca 2023.der")
7474

75+
def dbx_hashes_ms_amd64(self):
76+
return str(self._prefix / "secureboot_objects/DBX/amd64/DBXUpdate.bin")
77+
78+
def dbx_poison(self):
79+
return str(self._prefix / "varstored/dbx_poison.auth")
80+
7581

7682
SB_CERTS = _SecureBootCertList()
7783

@@ -90,7 +96,9 @@ def as_str(self):
9096
image_security_database_guid = GUID('d719b2cb-3d3a-4596-a3bc-dad00e67656f')
9197

9298
# Variable attributes for time based authentication attrs
99+
# Refer to https://uefi.org/specs/UEFI/2.11/08_Services_Runtime_Services.html#getvariable
93100
EFI_AT_ATTRS = 0x27
101+
EFI_VARIABLE_APPEND_WRITE = 0x40
94102

95103
time_seed = datetime.now()
96104
time_offset = 1

tests/uefi_sb/test_varstored_sb.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import logging
44

5-
from lib.efi import SB_CERTS, EFIAuth
5+
from lib.commands import SSHCommandFailed
6+
from lib.efi import EFI_AT_ATTRS, EFI_VARIABLE_APPEND_WRITE, SB_CERTS, EFIAuth, image_security_database_guid
67
from lib.vm import VM
78

89
from .utils import (
@@ -87,6 +88,45 @@ def test_sb_off_really_means_off(self, uefi_vm):
8788
logging.info("Check that SB is NOT enabled according to the OS.")
8889
assert not vm.booted_with_secureboot()
8990

91+
def test_append_with_default(self, uefi_vm: VM):
92+
vm = uefi_vm
93+
vm.host.pool.clear_custom_uefi_certs()
94+
vm.set_uefi_user_mode()
95+
vm.set_variable_from_file(
96+
SB_CERTS.dbx_hashes_ms_amd64(),
97+
image_security_database_guid,
98+
"dbx",
99+
EFI_AT_ATTRS | EFI_VARIABLE_APPEND_WRITE,
100+
)
101+
vm.start()
102+
vm.wait_for_vm_running_and_ssh_up()
103+
104+
def test_append_with_poison(self, uefi_vm: VM):
105+
"""
106+
Context: https://xcp-ng.org/blog/2025/10/30/xcp-ng-8-3-varstored-update-unbootable-vm-risk-and-remediation/
107+
108+
In short, the dbx variable previously used in the bad update did not use the Microsoft owner GUID, preventing
109+
deduplication of EFI signature data entries during an append call. Normally, this would not cause the VM to
110+
crash; except varstored does not check for the variable data length on append, triggering the issue.
111+
"""
112+
vm = uefi_vm
113+
vm.host.pool.clear_custom_uefi_certs()
114+
vm.set_uefi_user_mode()
115+
vm.set_variable_from_file(SB_CERTS.dbx_poison(), image_security_database_guid, "dbx", EFI_AT_ATTRS)
116+
try:
117+
vm.set_variable_from_file(
118+
SB_CERTS.dbx_hashes_ms_amd64(),
119+
image_security_database_guid,
120+
"dbx",
121+
EFI_AT_ATTRS | EFI_VARIABLE_APPEND_WRITE,
122+
)
123+
except SSHCommandFailed:
124+
# Appending the MS dbx may succeed or fail, doesn't matter, as appending the poison may not necessarily take
125+
# dbx over the DATA_LIMIT. The important thing is that the VM boots up following this append attempt.
126+
pass
127+
vm.start()
128+
vm.wait_for_vm_running_and_ssh_up()
129+
90130

91131
@pytest.mark.usefixtures("host_at_least_8_3")
92132
@pytest.mark.usefixtures("windows_vm")

0 commit comments

Comments
 (0)