AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 39 Bitcoin

fix(storage): make flash area bounds checks overflow-safe

Public commit record

What the developer wrote

Authored by tychovrahe

90/100 · Strong
fix(storage): make flash area bounds checks overflow-safe

Both bounds checks added an offset to a size in `uint32_t` before comparing
against the limit:

flash_area_get_address(): offset + size <= subarea_size
flash_area_write_data_padded(): offset + total_size > flash_area_get_size()

A sufficiently large second operand wraps the sum to a small value, so the
comparison passes and the function reports the range as fitting. Rewrite both
as subtractions, which cannot wrap. In `flash_area_get_address()` the
subtraction cannot underflow either, since the enclosing condition has already
established that the offset is below the sub-area size.

Neither check is reachable with such arguments today. The address lookup is
gated by `offset < subarea_size` first, so wrapping needs an almost 4 GB size
rather than a large offset, and no caller passes one - `secret_read()` is not
exposed as a syscall and every one of its call sites uses a constant or a
range-checked length. The padded write is backed by `get_sector_and_offset()`,
which re-derives the sector for every block written and fails for an offset
past the area. Both checks are nonetheless the documented bound that a future
caller would reasonably trust.

[no changelog]

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Uses a recognizable type or scope✓ Provides detailed explanatory context✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This commit fixes two overflow-prone safety checks in the Trezor firmware's flash storage code. The original checks added numbers together before comparing them to a limit; with specially crafted large values that addition could silently wrap around to a small number, making an out-of-bounds access look valid. The patch rewrites the checks using subtraction, which cannot wrap in the same way. The commit message says these particular checks are not reachable from current callers, so the immediate risk is low, but the change hardens the code against future misuse.

Recommended action

Treat as a low-risk defensive hardening patch. No urgent response is required because the commit message states the vulnerable arguments are unreachable from current callers. Include the fix in the next firmware release and consider adding static-analysis rules or tests to catch similar overflow-prone bounds checks elsewhere in storage code.

Security signals we found

01

Integer overflow in bounds check (CWE-190/CWE-680)

02

Potential out-of-bounds flash read/write if check bypassed

03

Defensive hardening of documented API boundary

04

No changelog entry despite security-relevant hardening

Risk score

Why this scored 39/100

Our methodology →
Potential impact 12/30
Exploitability 4/25
Stealth signal 6/15
Affected reach 5/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.