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

fix(core): stop ble_read() consuming a packet it cannot return

Public commit record

What the developer wrote

Authored by tychovrahe

95/100 · Strong
fix(core): stop ble_read() consuming a packet it cannot return

`ble_read()` dequeued from the RX queue and only then checked that the caller's
buffer was big enough. `tsqueue_dequeue()` resets the entry and advances the
read index unconditionally, and there is no re-enqueue on the error path, so a
buffer below `BLE_RX_PACKET_SIZE` silently destroyed a received packet and
reported zero bytes - indistinguishable to the caller from an empty queue.

The size test never needed the dequeued data. Once `read_len` is known to be
`BLE_DATA_SIZE`, `max_len < read_len - BLE_DATA_HEADER_SIZE` is just
`max_len < BLE_RX_PACKET_SIZE`, so hoist it above the dequeue. That also
retires an expression that was only in bounds thanks to the `||`
short-circuit ordering.

`py_iface_read()` rejects a short buffer before it gets here and the bootloader
wire layer requires an exact size, so the only way in is an applet calling the
`ble_read` syscall directly - which loses packets addressed to itself. No
caller changes behaviour: for every `max_len` at or above the packet size the
function does exactly what it did.

[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✓ Mentions testing or verification
The short version

What changed, and why it matters

This commit fixes a bug in the Bluetooth code of Trezor hardware wallets. When a program asked to read a Bluetooth packet using a buffer that was too small, the code would first remove the packet from the receive queue and only then realize the buffer was too small. Because the removed packet was not put back, it was silently lost. The fix checks the buffer size before removing the packet, so an undersized read now simply reports 'nothing available' instead of destroying data. The commit notes that the only realistic way to trigger this is an applet making a direct system call with a too-small buffer, which would cause that applet to lose packets meant for it.

Recommended action

Treat as a low-severity reliability/defensive fix. No urgent action required beyond normal patch uptake. If the project tracks security-relevant fixes, this could be noted as a minor hardening change for the BLE syscall interface.

Security signals we found

01

Silent data loss / packet drop on undersized buffer

02

Race-free logic bug in Bluetooth RX queue handling

03

Potential denial-of-service against applet expecting BLE packets

04

Fix is defensive and preserves queue state on error path

Risk score

Why this scored 45/100

Our methodology →
Potential impact 12/30
Exploitability 7/25
Stealth signal 9/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.