fix: clamp PktLen in CFE_MSG_ComputeCheckSum to MAX_SB_MSG_SIZE - #2756
stark256-spec wants to merge 1 commit into
Conversation
CFE_MSG_GetSize() reads the loop bound directly from the attacker- controlled CCSDS Length field. Without an upper-bound check the while(PktLen--) loop iterates over PktLen bytes regardless of the actual allocated buffer, enabling an OOB heap read proportional to the difference between the claimed and actual message size. Clamp PktLen to CFE_MISSION_SB_MAX_SB_MSG_SIZE (the largest valid SB message) before entering the loop. A larger value indicates a malformed message and is treated as zero (returns 0xFF checksum), which will fail the subsequent validity check in the caller. Fixes nasa/cFS#2699
|
Following up on this — it's been open a few weeks with no review yet. Happy to address any feedback on the approach. If it would help move this toward the next CCB cycle, let me know if |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
Clamping to CFE_MISSION_SB_MAX_SB_MSG_SIZE bounds the worst-case read, but it does not prove the claimed packet length fits the actual backing buffer. A short buffer whose CCSDS length says 1 KB (still below the mission max) can still make this loop read past the object. Could this validation happen where the real buffer capacity is known, or otherwise make that size guarantee explicit?
|
You're right, and thanks for the careful read. Clamping to Tracing it: within cFE, So rather than leave a bound that implies more safety than it provides, I'd suggest either: (a) drop the clamp and make the size precondition explicit in the |
Fixes nasa/cFS#2699.
CFE_MSG_GetSize()reads the loop bound from the attacker-controlled CCSDS Length field. Without an upper-bound check,while(PktLen--)iterates over an attacker-chosen number of bytes regardless of the actual buffer, enabling an OOB heap read. Clamps PktLen toCFE_MISSION_SB_MAX_SB_MSG_SIZEbefore the loop; a larger value indicates a malformed message and is treated as zero.