Secure Boot & Firmware Updates
IoT & Embedded Security · Embedded Systems & Firmware track
6 min read
In this module
Keeping Firmware Trustworthy
A device's firmware defines its behaviour. If an attacker can modify the firmware, they own the device, period. Secure boot ensures the device only runs authorised firmware. Secure firmware updates ensure the device can be patched without opening up new attack vectors. Together, these mechanisms form the foundation of embedded device integrity.
Secure Boot Chains
Secure boot verifies every stage of the boot process before executing it. The chain starts from an immutable root of trust in hardware:
At each stage, the running code verifies the cryptographic signature of the next stage before transferring control. Any verification failure and the boot halts.
The root of trust is typically a public key hash stored in OTP fuses. The hash gets programmed during manufacturing and cannot be changed afterwards. The boot ROM compares the first-stage bootloader's signing key against this hash. If they match, the bootloader is trusted and can verify subsequent stages.
Secure boot's strength is that every component is verified. Its weakness is that a vulnerability in any stage compromises all subsequent stages. A bug in the boot ROM (which cannot be updated) is catastrophic because it undermines the entire chain permanently. This is why boot ROM code must be minimal and extensively audited.
The textbook case is checkm8, published in September 2019: a use-after-free in the USB DFU code of Apple's SecureROM affecting devices from the A5 through the A11 chips. Apple couldn't patch the ROM in shipped phones, so those devices stay exploitable for good. The ROM doesn't even need a software bug to fail. A well-timed voltage glitch can skip its signature check, as you saw in Fault Injection.
Code Signing for Firmware
Code signing uses asymmetric cryptography to verify firmware authenticity:
- Signing: The firmware author signs the firmware image with their private key (kept in an HSM)
- Distribution: The signed firmware (image + signature) is distributed to devices
- Verification: The device verifies the signature using the public key stored in its secure storage
# Sign firmware with OpenSSL (simplified)openssl dgst -sha256 -sign private_key.pem -out firmware.sig firmware.bin
# Verify signatureopenssl dgst -sha256 -verify public_key.pem -signature firmware.sig firmware.binThe signing key must be guarded with the highest security available. If the private key leaks, the attacker can sign malicious firmware that every device will happily accept. Key management best practices: store the key in an HSM, require multi-party authorisation for signing, keep an audit log of every signing operation.
Secure OTA Update Mechanisms
Over-the-air (OTA) firmware updates are essential for patching vulnerabilities in deployed devices. But the update mechanism itself must be secure:
Transport security: Use TLS to encrypt the update download, blocking interception and confirming the device is talking to the legitimate update server. Pin certificates to defeat MITM attacks.
Signature verification: Verify the firmware signature before installation. The device should refuse any firmware that isn't signed by the authorised key.
Anti-rollback protection: Keep a monotonically increasing version counter (in OTP fuses or protected storage). The bootloader refuses to install firmware with a version number lower than the current counter:
// Anti-rollback check in bootloaderuint32_t current_version = read_version_counter();uint32_t new_version = get_firmware_version(update_image);
if (new_version <= current_version) { reject_update("Rollback attempt detected"); return;}
// After successful installationincrement_version_counter(new_version);Fuse-backed counters are a finite resource: each increment burns at least one OTP bit, and a part may only have a few dozen to spare. Vendors usually bump the rollback counter only for security-relevant releases, keeping the full version number in ordinary signed metadata.
Atomic installation: Use an A/B partition scheme where the update is written to the inactive partition while the current firmware continues running. After the update is fully written and verified, the bootloader switches to the new partition on the next boot. If the new firmware fails to boot, the bootloader falls back to the old partition:
The trial state is the part people skip. If the bootloader commits to B the moment it's written, a firmware that crashes on boot bricks the device just as surely as a half-written flash. MCUboot, the bootloader Zephyr uses, works this way in its swap mode: a new image is booted as a test, and unless the running firmware marks itself confirmed, the next reset swaps the old image back.
Verified Boot
Verified boot extends secure boot past initial startup into the whole runtime. Every block read from the partition is verified against a hash tree (dm-verity on Android and ChromeOS works this way):
- A hash tree covers every block of the read-only partition
- The root hash is signed and verified during boot
- Each block read is hashed and checked against the tree, below the filesystem, so it knows nothing about files
- Any modification to any block gets caught the moment it's read
This stops persistent filesystem modifications dead, even if an attacker scores temporary code execution. The filesystem is effectively read-only from an integrity perspective.
Common Implementation Mistakes
Even devices that implement secure boot can have nasty flaws:
- Checking signature but not enforcing: The bootloader verifies the signature but boots the firmware regardless of the result (a logic bug, sometimes literally a missing
if) - Using symmetric keys for signing: If the verification key is the same as the signing key, extracting it from one device lets you sign malicious firmware for all devices
- No anti-rollback: The device accepts any signed firmware, including ancient versions with known vulnerabilities
- Update over HTTP: Downloading updates without encryption hands MITM attackers a firmware-replacement opportunity
- Partial verification: Only the kernel is verified; the root filesystem isn't
Shipping a device with secure boot and OTA updates is not enough. The manufacturer must commit to providing security updates for the device's entire deployment lifetime. A smart lock that is deployed for 10 years needs 10 years of security patches. Without this commitment, secure boot and OTA updates provide initial security but degrade over time as new vulnerabilities are discovered and never patched.