HeapCrash / Challenges / Anti-rollback check in the bootloader

Anti-rollback check in the bootloader

The bootloader refuses images older than a minimum version kept in a one-way OTP counter. Version 2.10.0 was rejected as 'older' than 2.9.3. After a bad 3.0.0 rolled back automatically, units refused to boot the 2.9.3 they fell back to. A researcher bricked a unit with a crafted, unsigned header.

The code

Embedded C for Cortex-M. It compiles. There are 3 real bugs in it: the kind that pass a bench test and fail in the field.

typedef struct {
    uint32_t magic;
    char     version[12];            /* "major.minor.patch" */
    uint32_t size;
    uint8_t  sig[64];
} img_hdr_t;

bool boot_check(const img_hdr_t *h)
{
    if (strcmp(h->version, min_version_str()) < 0) return false;
    otp_set_min_version(h->version);
    return verify_signature(h);
}

What an interviewer expects

The bugs, reference fixes and the follow-up question are in the practice app, after you've tried it.

Companies that test this

Matched on the skills each company's embedded roles emphasise.

Related challenges

Flag the lines, say what breaks, then fix it and build it with clang in your browser.

Find the bugs