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

fix(core): tie ble::read()'s length to its buffer

Public commit record

What the developer wrote

Authored by tychovrahe

85/100 · Strong
fix(core): tie ble::read()'s length to its buffer

`read()` took the buffer and the length the caller claims for it as separate
arguments, and passed the length straight to `ble_read()`. `ble_read()` writes
a full `BLE_RX_PACKET_SIZE` packet whenever the length it is given is at least
that big, so a caller passing a length larger than its buffer gets 244 bytes
written into something shorter.

The one caller, `py_iface_read()`, hands `read()` a Python-supplied buffer of
arbitrary size and passed the constant `RX_PACKET_SIZE`. It checks
`buf.len() < RX_PACKET_SIZE` first, so nothing is wrong today - but that check
is the only thing standing between a short bytearray and an overflow.

Derive the length from the buffer so the two cannot disagree. `ble_read()`
then refuses to write at all when the buffer is too small, and the check in
`py_iface_read()` is left to produce a clearer error rather than to keep us in
bounds. Saturate rather than fail the conversion: the length is only compared
against the packet size, so a buffer above 65535 bytes must keep working.

[no changelog]

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
✓ 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 a potential buffer overflow in the Bluetooth Low Energy (BLE) read function of the Trezor hardware wallet firmware. Previously, the function trusted the caller's claim about how large the buffer was, which could allow more data to be written into a smaller memory area than intended. The fix makes the function use the actual buffer size instead, removing that trust relationship and preventing a possible overflow.

Recommended action

Treat as a security-hardening fix. Review other Rust FFI wrappers for similar buffer/length split patterns. No immediate incident response is indicated because the current caller already enforces the size constraint, but the fix removes a fragile trust boundary that could become exploitable if the caller's check is ever bypassed or changed.

Security signals we found

01

Potential buffer overflow due to mismatched buffer/length arguments in unsafe FFI boundary

02

Removal of caller-supplied length in favor of buffer-derived length

03

Defensive API hardening in Bluetooth transport layer

04

Saturating cast from usize to u16 to avoid panics on oversized buffers

Risk score

Why this scored 58/100

Our methodology →
Potential impact 18/30
Exploitability 10/25
Stealth signal 8/15
Affected reach 10/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.