Anti-rollback with one-time fuses
Refuse old, vulnerable firmware by its security version, counted in one-time-programmable fuses. A medium embedded C problem (OTA updates and rollback), run…
medium · OTA updates and rollback · ota · security · otp · secure-boot
An attacker who can install a signed but old firmware can reopen a vulnerability that was already fixed. To prevent that, each image carries a security version, and the chip records the lowest one it will accept in fuses that can never be un-burned.
Write:
image_allowed(img): true ifimg->security_versionis at least the number of burned fuses, and at most 32.image_confirmed(img): called once a new image has booted and confirmed itself. Burn fuses so that the number burned equals the image's security version. Burn the lowest unburned bits, never more than needed, and do nothing if enough are burned already.
Use otp_burn as few times as you like, but never burn a bit that is not needed.
Starter code
bool image_allowed(const img_t *img) {
return img->version >= otp_read();
}
void image_confirmed(const img_t *img) {
otp_burn(img->security_version);
}Example tests
Updates, then a downgrade attempt
try_image(500, 1);
try_image(503, 1);
try_image(600, 3);
try_image(503, 1);Expected output:
v500 (security 1): allowed, fuses 0x00000001
v503 (security 1): allowed, fuses 0x00000001
v600 (security 3): allowed, fuses 0x00000007
v503 (security 1): refusedLearn it first
- OTA updates and rollback · A/B slots, delta updates, rollback and signing.
More OTA updates and rollback problems
- Pick the slot to boot · Boot a new update on trial, and roll back if it never confirms itself.
- Is this image safe to jump to? · Check a firmware image's header, bounds, CRC and vector table before a bootloader starts it.
- Receive an update in chunks · Write update chunks to the spare slot in order, ignore resends, refuse gaps and overruns, and check the CRC at the end.
- Resume an update after a power cut · Keep download progress in an append-only flash journal, and find where to resume even after a torn write.
- Thermostat fleet: boot the update or roll back · Decide which firmware slot to boot, trying a new update a few times before rolling back.