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

SFT-7909: size the se_read copy from the caller's buffer

Public commit record

What the developer wrote

Authored by Jack

85/100 · Strong
SFT-7909: size the se_read copy from the caller's buffer

se_read() took its copy length from `actual`, the count of bytes that arrived on
the bus, rather than from `len`, the size of the buffer the caller supplied. tmp
only ever holds len + 3 bytes, because deserialize() clamps into it, so `actual`
describes neither the source nor the destination. Copy `len`.

check_crc() declared its length as uint8_t while its caller passes an int, so a
value above 255 wrapped before being compared against the response's count byte,
and a wrapped value can match a count that does not describe the response. Widen
the parameter. The count comparison still bounds it to a uint8_t before the CRC
walk, which is now said with a cast rather than left to the implicit conversion.

Verified by extracting check_crc() and se_crc16_chain() into a host harness and
running both signatures side by side: a well-formed seven-byte response passes
either way, a count of 263 is refused by the widened parameter and accepted by
the narrow one, and a mismatched count is refused by both.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode
The short version

What changed, and why it matters

This commit fixes two related bugs in the firmware that talks to the secure element chip inside the Passport hardware wallet. First, when reading data back from the secure element, the code was copying a number of bytes based on how many bytes arrived on the wire (`actual`) instead of how many bytes the caller's buffer could hold (`len`). That could overflow the caller's buffer if more bytes arrived than expected. Second, a CRC-check function used an 8-bit length variable, so any length above 255 would wrap around to a small number and could falsely match the response's count byte, letting an invalid or truncated response pass verification. The patch copies only `len` bytes and widens the length variable to an int, with an explicit cast only after it has been validated against the count byte.

Recommended action

Treat this as a security fix and include it in the next firmware release. Review other secure-element read/write paths for similar mismatches between bus-received length and caller buffer size. Consider whether the `actual - 3` arithmetic elsewhere in `se_read_response()` and `se_read()` needs additional bounds checks, and ensure callers cannot pass a `len` larger than the actual response payload.

Security signals we found

01

Buffer overflow / over-read in secure-element read path

02

Integer width mismatch leading to bypassable length validation

03

CRC length check could be defeated by uint8_t wraparound

04

Fix verified by host harness comparing old and new signatures

05

Secure-element interface code in hardware wallet firmware

Risk score

Why this scored 72/100

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