Running only trusted code on any computer is an obviously important feature from a security perspective (not such much from a freedom point of view, but that’s another discussion), but for whatever reason people tend to think of this starting with the operating system. Of course having a secure operating system is a key part of this, but it’s worthless if you can load untrusted code before it even loads.
This vector for attacks has been described multiple times by several different authors. Regardless of the specifics of the attack, the main problem is that, unless you establish a trust chain between the hardware, the firmware (i.e. BIOS, UEFI, etc), bootloader and the operating system, there’s nothing preventing malicious code from infecting right before our OS loads. And since the code will have full access to the hardware, it can use different techniques to be difficult or even impossible to detect, while still having a great potential for damage.
The way a PC boots
If we look at the traditional way PCs used to boot (that is before UEFI became common), we have 3 links in this chain: CPU, BIOS, boot sector, bootloader and OS.
The CPU is completely oblivious of any verification — it will just execute the code indicated by the reset vector, which normally would point to the BIOS (but which a malicious actor could modify to point to somewhere else, like an external ROM or even modified code within the BIOS itself). No verification here.
The BIOS will then run, initializing hardware and will eventually start the bootstrap process. Regardless of the boot device (which you can usually change at will), the boot sector would be loaded and control transferred to it without any verification. Again, this happens because there’s no verification.
The boot sector will then try to load some kind of loader. In MS-DOS, this used to be a section of IO.SYS (if I remember correctly). With Windows NT (and all its more recent family) it’s NTLDR. With Linux, that usually Grub’s first stage. But in all cases, regardless of the logic to do the actual loading, no verification is normally done and control is transferred silently.
While this part could get more complicated, like hardware detection to decide which OS kernel load, it will load something and blindly jump to it, starting the OS. Again, usually no verification.
While this process has, for the most part, worked fine for more than 20 years, it was always vulnerable to a malicious actor replacing any of the pieces with a malicious one. For example, boot sector viruses were common in the DOS-era (such as Stoned or Bleah).
Enter Secure Boot
While there are many examples of Secure Boot (including Trusted Boot in PCs with UEFI), all of them have the same idea in mind: ensuring only trusted code is executed throughout the boot process.
In this article, I’m going to describe the HABv4 by NXP. I’ve been using this functionality on my USB Armory mkII device from F-Secure Foundry. This will provide a simple, yet robust example of secure boot.
High-Assurance Boot v4 (HABv4)
HAB (also referred as High-Availability-Boot in some documents) is NXP’s implementation of Secure Boot, supported in several of their SoCs (though I will use the iMX 6 series in this article).

The first part is establishing trust in the CPU. Admittedly, this is not usually practical. However, the implementation takes a clever approach. Instead of making the reset vector user-controllable, there is an embedded ROM fused in the SoC during manufacturing. Every reset operation will begin executing this ROM, doesn’t matter what you try.
This ROM, called the Boot ROM, is 96KB long and cannot be modified by any means. It contains a nice set of functionality besides loading, such as DFU, JTAG, debug interface, programming API, etc. When is starts, it will initialize the hardware and try to load the boot loader from one of the MMC channels. Assuming it succeeded, it will check the image’s digital signature and make sure its signing key matches one of the keys fused in the SoC. If either the signature doesn’t match (indicating a modified bootloader) or if it’s signed by an unrecognized key (indicating a tampered bootloader), it will not transfer control to it.
The bootloader, usually U-Boot, will run and do its usual execution. But in the end it will load a FIT image. This type of image contains one of more sections, each containing a hash (usually SHA-256) representing that part. Finally, it contains a digital signature of all the hashes. Thus, you can ensure that none of the parts of the image have been modified. But U-Boot also contains an embedded public key (in the form of a certificate). Thus, it will check if the signature was made by the private key corresponding to that specific public key. It will only transfer control if the signature is true and correct.
Keeping trust within the OS
Now we’ve started the Linux kernel and we’re loading the system. However, there’s one final place where you can compromise the kernel-space security: kernel modules. Since Linux is a monolithic operating system, everything runs in the same kernel space. Thus, any misbehaving kernel module could access any other kernel memory. And this is why it’s so dangerous.
One approach would be to disable loadable modules completely and have every driver you need built-in into the kernel image. However, this is not always possible (one reason being GPL-related licensing issues). This means that in most cases we must have loadable kernel modules enabled.
Fortunately, the Linux kernel includes support for signature verification and enforcing, though it’s not enabled by default. Much like U-Boot, a certificate is embedded into the kernel and any module is checked for a valid signature that matches the embedded certificate. Only after a valid signature is verified the module is allowed to execute. And this is the final link of our trust chain.
By checking a digital signature in each part of this long process, we have completely ensured that our whole kernel-space is running trusted code. That is, we’re pretty sure there’s nothing hiding from us in the form of a rootkit or similar.
Weaknesses
This method, as you can always expect, is far from perfect.
Suppose there’s a security issue in the Linux kernel that allows privilege escalation from userspace or somehow making an untrusted kernel module to load. That would defeat the whole purpose of the trust chain, since the kernel space would be open to untrusted code. You could fix the issue and update the kernel, but still a malicious actor could downgrade the kernel back to a vulnerable version. Even updating U-Boot with a new certificate (thus making old versions no longer boot) would be a moot point, because U-Boot itself could be rewritten to an old version.
Another weakness is U-Boot itself. If some vulnerability is found on it, like making it possible to boot an untrusted image, the trust chain would be broken. Since there’s no downgrade protection (which is not exactly true, more on this later), an attacker could always use an old, vulnerable version.
But this method does have a final possibility if you need to prevent a downgrading of your bootloader. During initial configuration of secure boot (or “closed” mode, as indicated by NXP), you fuse 4 keys to the SoC in the form of OTP fuses. Yes, not 1, but 4. The device will run code provided that it’s signed by any of them. That is, unless you revoke them. Revocation works also with OTP fuses. By default all the revocation fuses are “1”, which means that the associated key is not revoked. When you revoke a key, the fuse will turn to “0” and code signed with that key will no longer be accepted. However, only keys 1-3 can be revoked. Key 4 cannot be revoked. This leaves you with 4 opportunities to update your bootloader and prevent downgrade. After that, you’ll be stuck with key 4 forever.
Finally, the boot ROM cannot be updated without a new silicon revision. This means that if a vulnerability is found on it, there’s no possibility of a software fix. Only an updated revision of the SoC would fix it, meaning it’s very expensive to replace.
Final Words
While trust chains are well-established methods for ensuring that only trusted code is loaded, any chain is as strong as its weakest link. You only need to find a vulnerability in one link to bring the whole chain down. Still, it can be made pretty secure.