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

fix(core): validate length in the nRF service callbacks

Public commit record

What the developer wrote

Authored by tychovrahe

85/100 · Strong
fix(core): validate length in the nRF service callbacks

`nrf_management_rx_cb()` and `nrf_test_cb()` select on `data[0]` without
checking that a byte is present, and the two management handlers went further
on the same assumption, computing `len - 1` and clamping the result with
MIN(). A zero-length frame turned that subtraction into 4294967295, so the
clamp always picked the full struct size.

The reads stayed inside the SPI frame buffer, so nothing was out of bounds.
The defect is that a truncated response was accepted as a complete one:

- a one-byte MGMT_RESP_INFO set `info_valid` while leaving `drv->info`
holding whatever a previous exchange left there,
- a one-byte MGMT_RESP_AUTH_RESPONSE set `auth_data_valid` with `auth_data`
still zeroed, which `nrf_authenticate()` then fed to the MAC comparison.

Both fail closed, but `nrf_authenticate()` gates boot in production builds and
has no business deciding anything from a frame the nRF never filled in.

Require the whole payload before marking the state valid, and set the flag
after the copy rather than before. The minimums match what the nRF sends:
`send_info()` transmits `1 + sizeof(nrf_info_t)` bytes and
`mgmt_process_challenge()` more than the digest we read. An older nRF that
sent less would now fail `nrf_get_info()` and fall through to the SMP path,
which forces an update - the outcome we want.

This is the same defect class as the recent fix to
`ble_process_rx_msg_mac()`; these were the remaining callbacks.

[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
The short version

What changed, and why it matters

This commit fixes a bug in the Trezor hardware wallet's code that talks to the nRF wireless chip over SPI. The code read the first byte of a received message to decide what kind of response it was, without first checking whether any bytes had actually been received. For two important response types—device info and authentication data—it then marked the data as 'valid' before copying it. A zero-length or truncated message could therefore make the device believe it had received valid authentication data when it had not. The device 'fails closed' (it does not unlock anything from bad data), but the bug could still let an empty or truncated frame influence the boot-time authentication check, which is not a safe design. The fix requires the full expected payload length before marking anything valid and moves the 'valid' flag to after the copy.

Recommended action

Apply the patch. Ensure all nRF/Bluetooth SPI callbacks validate minimum frame length before indexing `data[0]` and before marking any parsed state as valid. Audit remaining callbacks for the same pattern (set-valid-then-copy). Consider adding static analysis rules to catch `len - 1` on unsigned lengths and validity-flag ordering issues.

Security signals we found

01

Integer underflow in length calculation: `len - 1` with `uint32_t len == 0` produces `UINT32_MAX`

02

Use of untrusted length in `MIN()` without minimum-length validation

03

Validity flag set before data copy, allowing truncated frames to be treated as valid

04

Boot-gating authentication decision influenced by unvalidated nRF frame

05

Same defect class as a prior fix to `ble_process_rx_msg_mac()`

Risk score

Why this scored 62/100

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