Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomize SCM_REVISION address in firmware #4468

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

andrewkozlik
Copy link
Contributor

@andrewkozlik andrewkozlik commented Jan 2, 2025

Implements https://github.com/satoshilabs/trezor-firmware/issues/189.
Replaces https://github.com/satoshilabs/trezor-firmware/pull/190.

Problem

When a firmware update is loaded onto a fake Trezor device, a malicious bootloader may automatically extract the revision ID of the firmware update. The malicious firmware on the device may then use the extracted revision ID to convince Suite that the firmware was successfully updated when in fact the malicious firmware is running on the device all along. This PR makes it difficult to automatically find the firmware revision ID in the firmware binary file by randomizing the address of the SCM_REVISION string in the firmware binary. (The address randomization is deterministic so that deterministic builds are preserved.)

Solution

  1. I defined SCM_REVISION as a global symbol in a separate file core/embed/util/scm_revision/scm_revision.c, so that it will be placed into a distinct object file separate from all other symbols and constants which could otherwise be used to easily locate it.
  2. In SConscript.firmware I shuffle the list of object files deterministically based on the value of SCM_REVISION itself. Based on observation of the resulting binary files, this results in the linker shuffling the strings in the firmware binary.
    random.Random(SCM_REVISION).shuffle(obj_program)

@andrewkozlik andrewkozlik added core Trezor Core firmware. Runs on Trezor Model T and T2B1. R&D Research and development team related labels Jan 2, 2025
@andrewkozlik andrewkozlik self-assigned this Jan 2, 2025
@andrewkozlik andrewkozlik requested a review from prusnak as a code owner January 2, 2025 21:08
Copy link

github-actions bot commented Jan 2, 2025

core UI changes device test click test persistence test
T2T1 Model T test(screens) main(screens) test(screens) main(screens) test(screens) main(screens)
T3B1 Safe 3 test(screens) main(screens) test(screens) main(screens) test(screens) main(screens)
T3T1 Safe 5 test(screens) main(screens) test(screens) main(screens) test(screens) main(screens)
All main(screens)

core/SConscript.kernel Outdated Show resolved Hide resolved
core/SConscript.kernel Outdated Show resolved Hide resolved
core/embed/util/scm_revision/inc/util/scm_revision.h Outdated Show resolved Hide resolved
@andrewkozlik andrewkozlik force-pushed the andrewkozlik/scm_revision branch from 883f54f to ef6ccf5 Compare January 3, 2025 08:49
@andrewkozlik andrewkozlik merged commit 83a96f7 into main Jan 3, 2025
94 checks passed
@andrewkozlik andrewkozlik deleted the andrewkozlik/scm_revision branch January 3, 2025 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Trezor Core firmware. Runs on Trezor Model T and T2B1. R&D Research and development team related
Projects
Status: 🤝 Needs QA
Development

Successfully merging this pull request may close these issues.

2 participants