refactor(core/bootloader): commit the firmware version separately from checking it [no changelog]
What changed, and why it matters
This bootloader change fixes a side effect where simply asking the device for its status could permanently change a security counter on the device. Before, a routine called fw_check() both inspected the firmware and updated the rollback counter. Now the inspection is read-only, and the actual update is done only at deliberate points such as booting. This prevents a half-written firmware update or a status query from locking the device to a version before the firmware is fully verified and installed.
Treat this as a security-hardening fix and include it in the next bootloader release. Review other bootloader paths that call fw_check() to confirm none still expect the old commit side effect. Verify that the pre-jump re-verification commit and post-reboot commit cover all intended rollback-counter update cases.
Security signals we found
Rollback counter was written before image contents were verified
Status queries during firmware upload could commit a monotonic version while flash image was half-written
Separation of read-only verification from state-mutating commit
Debug link path newly exposed the side effect during upload
Glitch protection backup field present but unchanged
Evidence from the diff
The patch refactors fw_check() in the Trezor bootloader so it no longer calls ensure_firmware_min_version() as a side effect. Instead it records version_trusted and monotonic in fw_check_info_t. A new fw_commit_min_version() is introduced and called explicitly in the boot path after fw_check(). The pre-jump re-verification keeps its own commit, and the update flow continues not to commit until the following reboot. This removes write side effects from status queries (GetFeatures over wire and debug link) during firmware upload when flash may be half-written.
Changed components
core/embed/projects/bootloader/fw_check.ccore/embed/projects/bootloader/fw_check.hcore/embed/projects/bootloader/main.cInspect captured patch +33 / −1
### core/embed/projects/bootloader/fw_check.c
@@ -146,7 +146,8 @@ void fw_check(fw_check_info_t *fw_info) {
#endif
if (sectrue == secmon_valid) {
- ensure_firmware_min_version(hdr->monotonic);
+ fw_info->version_trusted = secmon_valid;
+ fw_info->monotonic = hdr->monotonic;
fw_info->firmware_present = check_image_contents(
hdr, IMAGE_HEADER_SIZE + vhdr.hdrlen, &FIRMWARE_AREA);
fw_info->firmware_present_backup = fw_info->firmware_present;
@@ -266,3 +267,9 @@ void fw_run_prepare(fw_run_info_t *info) {
IMAGE_CODE_ALIGN(FIRMWARE_START + vhdr.hdrlen + IMAGE_HEADER_SIZE) +
secmon_code_offset;
}
+
+void fw_commit_min_version(const fw_check_info_t *fw_info) {
+ if (sectrue == fw_info->version_trusted) {
+ ensure_firmware_min_version(fw_info->monotonic);
+ }
+}
### core/embed/projects/bootloader/fw_check.h
@@ -65,6 +65,16 @@ firmware image is present. */
volatile secbool firmware_present_backup; /**< True if a valid, bootable
firmware image is present - backup for
glitch protection. */
+
+ volatile secbool version_trusted; /**< True if the firmware header (and the
+ secure monitor, where verified) passed all
+ checks, so that `monotonic` may be committed
+ to the rollback counter. Independent of
+ `firmware_present`: a signed header with a
+ corrupt body still counts. */
+
+ uint8_t monotonic; /**< Monotonic version from the firmware header; valid
+ when `version_trusted` is set. */
} fw_check_info_t;
/**
@@ -89,6 +99,18 @@ secbool __wur check_vendor_header_lock(const vendor_header *const vhdr);
*/
void fw_check(fw_check_info_t *fw_info);
+/**
+ * @brief Commit the firmware's monotonic version to the rollback counter.
+ *
+ * Does nothing unless `fw_check()` found the header trusted
+ * (`version_trusted`). `fw_check()` itself never writes anything, so status
+ * queries over the wire or the debug link can call it freely; the boot path
+ * calls this right after it.
+ *
+ * @param fw_info Result of `fw_check()`.
+ */
+void fw_commit_min_version(const fw_check_info_t *fw_info);
+
/**
* @brief Everything `real_jump_to_firmware()` needs to hand control to the
* installed firmware, resolved by the layout-specific verification/policy code.
### core/embed/projects/bootloader/main.c
@@ -562,6 +562,9 @@ int bootloader_main(void) {
fw_check_info_t fw;
fw_check(&fw);
+ // A trusted header forbids going below its version from now on, whether
+ // or not its body is intact.
+ fw_commit_min_version(&fw);
#if PRODUCTION && !defined STM32U5
// for STM32U5, this check is moved to boardloaderWhy this scored 63/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.