Secure Enclave Firmware: Why Less Code Can Be Safer
See how a confidential VM replaced million-line OVMF firmware with 300 lines of assembly—and what moving security checks to measured build artifacts changes.

From a Million Lines of Firmware to 300 Lines of Assembly
Firmware is easy to miss - until it sits on the security boundary. In a confidential virtual machine, it runs before the operating system and helps determine what the machine will trust. If that firmware can be manipulated, hardware-backed protections may not guarantee what users think they're guaranteeing.
Tinfoil's response wasn't to harden everything in its general-purpose firmware. It asked a simpler question: what does firmware actually need to do? By moving the kernel, initramfs, and much of the machine configuration into a measured build artifact, the team swapped out more than a million lines of OVMF code for roughly 300 lines of assembly, with no dependencies.
This isn't an argument for custom firmware as a lifestyle. It's a concrete example of a security principle: reduce what exposed code has to handle from untrusted input, and make the important state inspectable before runtime. In this article, I'll walk through how the design works, what it moves out of firmware, and where the trade-offs show up.
Why does firmware matter in a confidential VM?
A confidential virtual machine (CVM) uses hardware features to protect guest memory from the host. On different platforms, that protection can come from technologies such as Intel TDX or AMD SEV-SNP. The hardware can also produce an attestation - evidence about the machine's initial state that another party can verify.
In most setups, the host isn't inside the guest's trust boundary. That matters. Traditional virtualization security often focuses on the guest escaping into the host. With confidential computing, you also have to worry about the reverse: a hostile or compromised host trying to influence what runs inside the guest.
Boot is part of the security boundary
A CVM's launch state is measured by the hardware. In a conventional boot flow, that measured state includes the firmware. The firmware then loads the operating system and measures or verifies what comes next. So the integrity of later software still depends on the firmware behaving correctly after the hardware has taken the initial measurement.
That gives firmware a real role. If it accepts malicious host input, or has a bug that can be triggered during boot, it could load software that doesn't match what you expected. The machine might still produce an attestation, but the link between that evidence and the operating system actually running can be weaker than it looks.
General-purpose firmware carries general-purpose surface area
Tinfoil previously used OVMF, a widely used open-source firmware package for virtual machines. OVMF supports lots of platforms and features, including network boot, device drivers, runtime services, and boot management. That breadth helps when one firmware package needs to work across many configurations.
But even a workload that only uses a small slice of those capabilities still has to carry the code and input paths that come with the bigger package. The source describes OVMF as having more than a million lines of C, and points to a recently disclosed vulnerability in its network stack - functionality Tinfoil didn't need for its boot flow.
So the question wasn't "is OVMF popular?" or "has open-source review helped?" The real question was whether the deployed system needed all of that behavior inside something security-critical. A widely used, heavily reviewed project can be a good fit when compatibility matters. It can also be more than what a tightly controlled environment should rely on.
How can measured launch state replace runtime firmware work?
The redesign separates two jobs that were previously bundled together: defining the machine's initial state and handing control to Linux. Tinfoil uses the Independent Guest Virtual Machine (IGVM) file format to describe the guest's initial memory layout. The build system then creates an artifact containing the firmware (in effect, only the minimal role), kernel, initramfs, command line, and the relevant platform data.
Instead of asking firmware to load and measure the operating system after launch, the design puts those components into memory before the enclave starts. The hardware measures that initial state as a whole. On TDX, the key launch measurement is MRTD; on SEV-SNP, it's the launch digest.
Move decisions to build time
This shifts work from a live boot path into the build process. The build system generates page tables, fixed ACPI tables and templates, and the supported memory layouts. Because the resulting IGVM artifact is produced ahead of time, it can be measured, inspected, and compared across releases.
There's also a trust distinction here. If a runtime component parses attacker-controlled input, you have to assess it across every input shape an attacker can provide. A generated artifact is different: it's a real object reviewers can examine byte-for-byte, compare across versions, and tie to the measurement. The generator still has to be correct - but it isn't processing fresh host-provided configuration during each guest boot.
None of this removes risk. If the generator has a bug, it can produce a faulty artifact that affects every guest built from it. The difference is that the output is consistent and available for review, rather than being assembled dynamically from untrusted input at runtime.
Keep only bounded host choices
Some configuration still needs to vary. Tinfoil needs to launch machines with different amounts of memory and different CPU counts without building a new image for every possible resource allocation.
To handle that, the design predefines the shape of the memory map and includes it in the measured state. At boot, the host provides the actual map and memory size. The minimal firmware checks that the map matches the expected layout; only the total RAM amount can vary within the supported bounds. If the host supplies a map with the wrong shape, the machine fails to boot.
CPU configuration follows a similar idea. The system pre-builds ACPI tables, including the Multiple APIC Description Table (MADT), and the firmware checks the CPU count reported by the host before updating the relevant entry. These checks limit what the host can influence, instead of letting it define arbitrary platform tables.
Once the kernel, initramfs, command line, and required structures are already in memory, the firmware's final job is straightforward: set up the required x86 state and jump to Linux. After that handoff, the firmware doesn't run again.
What did the minimal firmware keep, move, or remove?
The result is approximately 300 lines of open-source assembly instead of roughly a million lines of OVMF. The key change isn't "a smaller version of all firmware features." Most features were moved to another stage or removed because the deployment didn't need them.
Jobs moved to measured build artifacts
Page tables and the global descriptor table are generated ahead of time. So are the kernel, initramfs, command line, fixed ACPI tables, and supported memory layouts. Since these elements are part of the launch state, hardware measures them before the firmware hands control to Linux.
It also changes the firmware's role in the measurement chain. Firmware no longer loads the operating system and then decides what to measure. The expected code and supporting state are already inside the measured image.
Jobs handled by Linux or deleted
Some responsibilities move to the operating system. Linux handles PCI enumeration and brings up additional CPUs. It can accept memory pages as needed, instead of requiring firmware to manage every page before handoff. The host stops the VM when it's time to shut down, so firmware doesn't need graceful-shutdown machinery.
Other features disappear because the deployment doesn't use them. There's no firmware boot manager, variable store, Secure Boot flow, network or disk driver stack, option ROM handling, or runtime service layer for the operating system.
That boundary is intentional, not a claim that Linux has no bugs. The point is that Linux already performs several of these jobs in confidential guests. Under the earlier arrangement, some work happened in both firmware and the kernel. Removing the firmware implementation avoids maintaining and exposing a second runtime path for tasks the system already relies on Linux to perform.
Reduce the places where the host controls parsed data
The source describes eight areas in the previous boot path where guest code parsed host-controlled bytes, including firmware configuration, ACPI-related data, SMBIOS, a variable store, virtual-device drivers, and option ROMs. In the new design, firmware keeps two bounded checks: the memory map and the CPU count.
That's more meaningful than a raw line-count comparison. Even a small binary can be unsafe if it parses complex attacker-controlled input. The security gain comes from reducing both the amount of runtime code and the number of ways untrusted host data can affect it.
What are the trade-offs of purpose-built firmware?
Purpose-built firmware works when you control the machine shapes and the boot requirements. It doesn't fit as well when you need to support many hardware platforms, lots of arbitrary devices, or configurations that change without rebuilding and revalidating the image.
Narrow support buys a smaller runtime boundary
General-purpose firmware adapts to many machines. Tinfoil's design supports a defined set of layouts. If QEMU changes a memory layout, the firmware may refuse to boot until the build configuration and measured artifacts get updated.
That's operational friction. It can slow a rollout and create work before a platform change is "supported." For a uniform fleet, the cost may be acceptable: the set of configurations is manageable, and the reduction in runtime behavior has real security value. For a broader cloud product, it could be a deal-breaker.
Build tools still belong in the trust model
Moving work to build time doesn't make it disappear. The table generator and image builder still need review, testing, and protection. They're part of the trusted computing base - software that has to be correct for the artifact to be trustworthy.
The key difference is where the risk lands. The generator isn't part of the live runtime trusted computing base in the same way a parser is when it runs on every boot in response to hostile host input. A generator bug can still produce bad output, but that output becomes a fixed artifact that can be diffed and examined. A runtime parser bug can sit quietly until an attacker supplies the exact input that triggers it.
So the comparison isn't "runtime code versus no code." It's "which code must process attacker-controlled input at runtime, and which outputs can be inspected independently before deployment?"
Minimal does not automatically mean secure
Custom firmware can be less mature than a widely used dependency. It might not have years of compatibility testing, and a small codebase can still contain serious logic errors. Cutting features helps only when the remaining behavior is clearly defined and tested against the real deployment requirements.
Tinfoil also considered Project Oak's Stage0, a smaller firmware intended for confidential virtual machines. That design still loads and measures the kernel and initramfs after launch and constructs platform tables from host-provided configuration. Those are reasonable choices for a component meant to handle varied machines. Under Tinfoil's threat model, generating the state ahead of time - and leaving firmware with fewer host inputs to parse - was the safer trade.
The general lesson isn't "every organization should write its own firmware." It's that a popular dependency isn't automatically the safest option when large parts of it fall outside what your product actually needs. Compare what you'd have to maintain in a custom component against the runtime attack surface and compatibility needs you truly have.
Conclusion: reduce runtime trust, not just code
Replacing a million-line firmware package with 300 lines of assembly is eye-catching, but the more useful part is what the architecture does behind that number. Tinfoil moved the kernel, initramfs, platform tables, and much of the machine definition into a measured build artifact. The remaining firmware performs a small set of checks on bounded host configuration and then hands control to Linux.
This narrows the live attack surface and makes the initial state easier to inspect. It also comes with real costs: build tooling becomes more important, supported configurations are narrower, and platform changes can require updating images.
When you're evaluating a security-critical dependency, start with the jobs your system actually needs. Figure out which decisions can be made and measured before runtime, which inputs must remain variable, and what compatibility trade-offs you're willing to accept. The goal isn't "the smallest codebase possible." It's the smallest runtime trust boundary that still fits the product.