SFT-7909: require a response long enough to fill the caller's buffer
What changed, and why it matters
This 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.
Treat this as a security-relevant fix and include it in the next firmware release. Review other fixed-length copies near deserialization paths for similar length assumptions. No immediate CVE coordination is required unless the vendor determines the leaked stack data can include sensitive material.
Security signals we found
Use of uninitialized/stack-residual data in a successful return path
Missing lower-bound length check before fixed-length copy
Secure-element communication parsing bug
Potential information disclosure via returned buffer contents
Evidence from the diff
In se_read(), a fixed-length memcpy of len bytes was performed after deserialize() wrote only actual received bytes into tmp[]. For OP_Info with len=4, a four-byte response passed the minimum-length check, skipped frame/CRC validation, and caused the copy to read tmp[1..4] even though only tmp[0..2] had been written by the transport. This returned one byte of uninitialized stack data with rc=0. The patch adds an explicit guard ‘if (actual < len + 3)’ before the copy, routing short responses through the existing retry path. The guard is placed after opcode checks because only OP_Info is vulnerable; other opcodes already imply this condition via check_crc() and length checks. Overlong responses remain accepted because the copy is bounded by len.
Changed components
ports/stm32/boards/Passport/common/se.cse_read() functionOP_Info secure-element response handlingInspect captured patch +18 / −0
### ports/stm32/boards/Passport/common/se.c
@@ -410,6 +410,24 @@ int se_read(uint8_t* data, uint8_t len) {
}
}
+ /*
+ * The response also has to be long enough to fill the caller's buffer.
+ * deserialize() only writes what arrived, so a short response leaves
+ * the tail of tmp untouched and the fixed-length copy below would hand
+ * back whatever the stack happened to hold.
+ *
+ * In practice this only bites OP_Info, which skips the checks above:
+ * for every other opcode check_crc() requires tmp[0] == actual while
+ * the length check requires tmp[0] == len + 3, so the two together
+ * already imply it. Retry rather than fail, matching the short-read
+ * arm, so a transient truncation gets another attempt.
+ */
+ if (actual < len + 3) {
+ ERR("short resp");
+ short_error++;
+ goto try_again;
+ }
+
/*
* Copy the length the caller asked for. `actual` counts what arrived on
* the bus, and tmp only ever holds len + 3 bytes, so it is not a boundWhy this scored 60/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.