Reclamation of UEFI-reserved Memory During Runtime
Posted: Thu Aug 01, 2024 10:08 am
Greetings to all.
I have recently been doing more work on my UEFI loader for fully encrypted boot media. For systems which can read and mount filesystems from ACPI NFIT information, this is working great: I plug in my prepared USB, power on, give the right password, the ramdisk is loaded, AES decryption completes, and control transfers to the disk's own stage-1 loader. Sick.
This is excellent for installation media. I can wall any OS installer supporting ACPI NFIT filesystems behind this crypto and create completely confidential and tamper-resistant installers. Once the installer does its job, the system reboots into the new OS. Great.
However, this system does not play so nicely with boot partitions that load a full, already-installed operating system. While it works--the initial ramdisk is decrypted and boots into the system--the amount of memory reserved from the first-stage UEFI chainloader (read: my work) remains after the boot process is completed. I want to release this reserved memory (ramdisk) after booting off it.
I was investigating options for runtime drivers, or using something using UEFI's Events and Signals support to release memory back to the runtime OS for use. It's not great always missing a substantial chunk of main memory after booting.
This seems to be a very specific request, and I'm not sure where to look for examples of doing so, so I am turning to this community for any help I can get.
I do of course plan on giving back and open-sourcing this project (i.e., sharing with the community) once the work is complete.
Thanks in advance for any input.
I have recently been doing more work on my UEFI loader for fully encrypted boot media. For systems which can read and mount filesystems from ACPI NFIT information, this is working great: I plug in my prepared USB, power on, give the right password, the ramdisk is loaded, AES decryption completes, and control transfers to the disk's own stage-1 loader. Sick.
This is excellent for installation media. I can wall any OS installer supporting ACPI NFIT filesystems behind this crypto and create completely confidential and tamper-resistant installers. Once the installer does its job, the system reboots into the new OS. Great.
However, this system does not play so nicely with boot partitions that load a full, already-installed operating system. While it works--the initial ramdisk is decrypted and boots into the system--the amount of memory reserved from the first-stage UEFI chainloader (read: my work) remains after the boot process is completed. I want to release this reserved memory (ramdisk) after booting off it.
I was investigating options for runtime drivers, or using something using UEFI's Events and Signals support to release memory back to the runtime OS for use. It's not great always missing a substantial chunk of main memory after booting.
This seems to be a very specific request, and I'm not sure where to look for examples of doing so, so I am turning to this community for any help I can get.
- Does anyone know where I might be able to start?
- What is the best and least "hacky" mechanism to use here?
- Should I even do this? Since the kernel is loaded from the initrd into a different memory location after booting completes, theoretically releasing the boot ramdisk should not affect any runtime operations. The boot ramdisk acts strictly as an initial and read-only filesystem.
I do of course plan on giving back and open-sourcing this project (i.e., sharing with the community) once the work is complete.
Thanks in advance for any input.