Commit message · JackSFT-7909: require a response long enough to fill the caller's buffer
Sizing the copy from len rather than from the transport count fixed the
overlong case and introduced a small one in the other direction. For OP_Info
with len=4, a response of exactly four bytes passes the minimum-length check
and skips the frame and CRC checks, so deserialize() writes tmp[0..3] and the
fixed-length copy reads tmp[1..4] -- one byte the transport never wrote --
then reports success.
Shown with a host harness compiling the real se_read(), se_read_response(),
deserialize(), check_crc() and se_crc16_chain() with only the transport and
logging replaced. A full response, then a truncated one, returned
data=11 22 33 ef with rc=0, where the transport had supplied only 11 22 33 and
ef was left in that stack slot by the preceding call.
Reject actual < len + 3 immediately before the copy, through the existing
retry path so a transient truncation gets another attempt. The guard sits
after the opcode checks on purpose: it only bites OP_Info, because for every
other opcode check_crc() requires tmp[0] == actual and the length check
requires tmp[0] == len + 3, which together already imply it. Keeping it there
also leaves the SE error-code path, which returns early on a four-byte
response, untouched.
Harness results with the guard: a full Info response still succeeds, the
truncated one returns -1 with the destination untouched, an overlong 263-byte
response still copies exactly len bytes without overflowing, and a normal
command's error response still surfaces last_error = 0xEE.
Overlong responses stay accepted rather than requiring actual == len + 3. The
comment in se_read_response() says framing is sometimes imperfect and junk can
arrive at the end, so an exact-equality gate risks refusing responses that work
today, and the overflow is already closed by copying len.
90/100 · StrongMessage clarity
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Names security-relevant behavior explicitly
Why it was queuedmemory safety
AI analysis · Moderate 60/100This commit fixes a firmware bug in how the Passport hardware wallet reads replies from its secure chip. When a certain type of reply (an 'info' response) was shorter than expected, the code could copy unread bytes from leftover stack memory into the caller's buffer and report success. That could leak small amounts of whatever data happened to be on the stack, or return incorrect info about the secure chip. The fix adds a length check so short replies are rejected and retried instead of being silently accepted.