Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 929 of 93612. IoT Connectivity and SecurityFree lesson

Managing Version Rollback and Security Anti-Rollback

Enforce version control policies that prevent attackers from downgrading device firmware to older versions with known security vulnerabilities.

In this lesson, you will learn how to implement hardware-enforced anti-rollback mechanisms to prevent attackers from re-installing older, vulnerable firmware versions.

The Problem: Version Rollback Attacks

Even if your firmware is signed and cryptographically verified, an attacker can perform a "version rollback attack." In this scenario, they flash an older, legitimate version of your firmware that was signed by your private key in the past but contains a known security flaw (e.g., a buffer overflow or a weak cryptographic implementation). Because the signature is valid, a standard Secure Boot process will accept the malicious, outdated image as authentic.

The Solution: Monotonic Counters

To defeat this, your device must maintain a monotonic counter—a hardware-backed storage element that can only be incremented and never decreased. This counter tracks the minimum version (or "security version number") allowed to execute on the device.

When a firmware image is created, it is assigned a version number within its signed metadata. During the boot sequence, the secure bootloader performs the following logic:

// Pseudo-code for Anti-Rollback check
uint32_t current_hw_version = read_otp_monotonic_counter();
uint32_t incoming_fw_version = get_fw_metadata_version(new_image);

if (incoming_fw_version < current_hw_version) {
    // REJECT: Attack detected! 
    panic("Rollback attempt blocked.");
} else if (incoming_fw_version > current_hw_version) {
    // UPDATE: New firmware is higher version; update the hardware counter.
    write_otp_monotonic_counter(incoming_fw_version);
    boot_firmware(new_image);
} else {
    // ACCEPT: Version matches, proceed to signature verification.
    verify_signature(new_image);
}

Implementing Hardware Backing

To be effective, this counter must be stored in tamper-resistant, non-volatile hardware, such as One-Time Programmable (OTP) memory or an internal eFuse array managed by the Root of Trust. If you store this counter in standard flash memory, an attacker could simply erase the sector to reset the counter, effectively disabling your protection. By using hardware eFuses, once you "blow" a bit to represent a new version, it is physically impossible to revert it to a lower state.

Key Takeaway: Always pair firmware signature verification with a hardware-backed monotonic counter to ensure that only the latest, most secure version of your firmware can ever be executed on the device.