From 67a75449a270804854c5cdae4b2b6a83c1fcd234 Mon Sep 17 00:00:00 2001 From: clover caruso Date: Thu, 22 Oct 2026 13:14:53 -0700 Subject: [PATCH] Preserve EFI state in prepared VM clones Keep signed EFI variables with the prepared disk when saving and cloning secure UEFI presets. A fresh variable store can trigger the upstream OpenSSL runtime address-map bug during Windows signed-variable updates: https://github.com/tianocore/edk2/issues/9769 The save/create regression also checks that clone credentials remain independent. Assisted-by: gpt-6.1-sol --- tools/dashboard-vms-test.py | 43 +++++++++++++++++++++++++++++++++++++ tools/vms.py | 8 ++++--- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/tools/dashboard-vms-test.py b/tools/dashboard-vms-test.py index 0ec362badd5edbf294be0f86212588953981046d..e30d4332323e6b118f6bd3cec4879172bb00df6a 100644 --- a/tools/dashboard-vms-test.py +++ b/tools/dashboard-vms-test.py @@ -22,6 +22,49 @@ spec.loader.exec_module(host) class VMTests(unittest.TestCase): + def test_secure_preset_retains_efi_state_but_generates_new_login(self): + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary).resolve() + disks = root / 'vms' + source = disks / 'template' + source.mkdir(parents=True) + (source / 'disk.qcow2').write_bytes(b'prepared disk') + (source / 'nvram.fd').write_bytes(b'prepared signed EFI variables') + code = root / 'code.fd' + code.write_bytes(b'firmware') + defaults = root / 'vars.fd' + defaults.write_bytes(b'fresh EFI variables') + xml = f''' + windowswindows-aarch64-nvme + 83886084 + hvm{code}{source / 'nvram.fd'} + ''' + def command(*args, **kwargs): + if args[0] == 'cp': + with os.fdopen(os.dup(int(args[-2].split('/')[-1])), 'rb') as incoming: + Path(args[-1]).write_bytes(incoming.read()) + elif args[:2] == ('qemu-img', 'convert'): + Path(args[-1]).write_bytes(Path(args[-2]).read_bytes()) + return json.dumps({'format': 'qcow2', 'virtual-size': 1024, 'format-specific': {'data': {}}}) + def virsh(*args, **kwargs): + return {'domstate': 'shut off', 'dumpxml': xml, 'pool-list': 'vms', 'pool-info': 'State: active'}.get(args[0], '') + with patch.object(vms, 'DISKS', disks), patch.object(vms, 'PRESETS', root / 'presets'), \ + patch.object(vms, 'command', side_effect=command), patch.object(vms, 'virsh', side_effect=virsh), \ + patch.object(vms, 'secure_firmware', return_value=(code, defaults)), \ + patch.dict(os.environ, {'SNOWGLOBE_VM_WINDOWS_ARM_EMULATOR': '/qemu-system-aarch64'}): + vms.save_preset({'name': 'template', 'id': 'prepared', 'os': 'Windows 11 Pro ARM64', + 'description': '', 'setup': 'windows-v4'}) + for name in ['first', 'second']: + vms.create({'name': name, 'description': '', 'image': 'prepared', 'mode': 'preset', + 'owner': 'fixture', 'username': name, 'vcpus': 4, 'memory': 8 * 2**30, + 'disk': 1024, 'start': False, 'autostart': False}) + self.assertEqual((disks / name / 'nvram.fd').read_bytes(), (source / 'nvram.fd').read_bytes()) + first = json.loads((disks / 'first' / 'access.json').read_text()) + second = json.loads((disks / 'second' / 'access.json').read_text()) + self.assertNotEqual(first['password'], second['password']) + self.assertEqual(first['username'], 'first') + self.assertEqual(second['username'], 'second') + def test_windows_setup_closes_milestone_files(self): for stage in ['ready', 'failed', 'restarting', 'personalizing']: def reply(action, name, payload, *args): diff --git a/tools/vms.py b/tools/vms.py index 8cd78b73d8f6ccc3b899ab80fb57bd0a2fade1b8..2f8b3abf959fa8d3c448bb715a11694043620b8e 100644 --- a/tools/vms.py +++ b/tools/vms.py @@ -585,10 +585,10 @@ def save_preset(spec): hardware_profile = inferred_profile(root) type_element = os_element.find("type") arch = type_element.get("arch", "x86_64") - details_profile = checked_profile(hardware_profile, platform, firmware, arch) - # Persistent firmware variables are needed for installers that only register an EFI boot entry. + checked_profile(hardware_profile, platform, firmware, arch) + # Boot entries and signed EFI variables belong to the prepared image. nvram = root.findtext("./os/nvram") - if nvram and not details_profile.get("secure"): + if nvram: with os.fdopen(open_regular(Path(nvram)), "rb") as incoming, (temporary / "nvram.fd").open("xb") as outgoing: shutil.copyfileobj(incoming, outgoing) preset = {"id": spec["id"], "os": spec["os"], "description": spec["description"], @@ -836,6 +836,8 @@ def create(spec, *, ai=False): if firmware == "uefi": if details_profile.get("secure"): code, variables = secure_firmware(details_profile["arch"]) + if preset and (PRESETS / selected / "nvram.fd").exists(): + variables = PRESETS / selected / "nvram.fd" nvram = directory / "nvram.fd" copy_regular(variables, nvram) loader = ET.SubElement(os_element, "loader", readonly="yes", type="pflash") -- 2.54.1