Repository navigation
Fix #2745, validate CFE_MSG_Init size and use OR for byte concatenation - #2821
philphauler wants to merge 3 commits into
Conversation
|
@philphauler Thank you for your contribution. Please resolve the workflow failures. |
6ffe6c4 to
5e83079
Compare
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
The PR is scoped as fixing all four findings from #2745, but the current head still leaves two of them untouched: the malformed CFE_MSG_CMD_HDR_INIT initializer in default_cfe_msg_hdr_priext.h, and the checksum walk in cfe_msg_sechdr_checksum.c (that file only has BOM/whitespace changes here). Could those two fixes be included, or should the PR scope/title be narrowed to the findings actually addressed?
|
Imma look more into it 🫡⚡️ |
…and use OR for byte concatenation CFE_MSG_Init used the caller's Size as the memset length before CFE_MSG_SetSize validated it, so an oversize argument cleared memory past the message buffer. Apply the same bounds CFE_MSG_SetSize enforces before the memset. CFE_MSG_GetSystem and CFE_MSG_GetSize concatenate header bytes with +; use | so the expression states a bit concatenation and survives a wider storage type. Findings 2 and 3 of nasa#2745 are not part of this change: the priext initializer was fixed by 13ed881 (nasa#2317) and the checksum walk needs a caller-provided bound, which is an API decision.
4164a5f to
4e2c757
Compare
|
Hi @sylvesterkaczmarek 👋 good call on the scope. Narrowed to findings 1 and 4 (4e2c757, squashed to one commit): finding 2 was already fixed upstream in 13ed881 (#2317) and finding 3 needs a decision on the BufLen API that does not belong in this PR. The size bound now mirrors CFE_MSG_SetSize (CFE_MSG_SIZE_OFFSET moved to cfe_msg_priv.h) and the UT adds the 65 KB-over-a-header and underflow cases. coverage-msg-ALL passes. Have a great day! |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
The scope is now clear and matches the implementation: findings 1 and 4 are addressed here, with the already-upstream and API-design items left out. The shared size offset and boundary tests make the CFE_MSG_Init fix consistent with CFE_MSG_SetSize, and the byte concatenation uses the intended unsigned shift/OR. My scope concern is resolved.
|
Eyyyy let's gooooo ⚡️🚀 |
CFE_MSG_Init calls CFE_MSG_SetSize (cfe_msg_ccsdspri.c:391) and returns its status, so the CCSDS-representable upper bound is already enforced by SetSize (Size > 0xFFFF + CFE_MSG_SIZE_OFFSET rejected there too) - it is not silently ignored or truncated. Init's own copy of that same upper bound, added in 4e2c757, duplicates SetSize's check but runs before the buffer is cleared, which is wrong for CFE_SB_SendMsg's documented flow: modules/cfe_testcase/src/sb_sendrecv_test.c:443-453 builds a message sized CFE_MISSION_SB_MAX_SB_MSG_SIZE + 16 (32784 bytes with the repo's default 32768-byte CFE_MISSION_SB_MAX_SB_MSG_SIZE, cfe_sb_interface_cfg.h) into a buffer allocated at exactly CFE_MISSION_SB_MAX_SB_MSG_SIZE, and expects CFE_MSG_Init to succeed (32784 is still under the CCSDS max of 0xFFFF + 7 = 65542) while CFE_SB_TransmitBuffer rejects it as CFE_SB_MSG_TOO_BIG against the real allocated buffer. Keep only the lower bound in Init (Size < CFE_MSG_SIZE_OFFSET, matching SetSize's own minimum and rejecting a memset shorter than the header); drop the upper bound and let CFE_SB_TransmitBuffer/CFE_MISSION_SB_MAX_SB_MSG_SIZE do that job against the real buffer, as SetSize already does independently for the CCSDS wire-format limit. modules/msg/ut-coverage/test_cfe_msg_init.c: removed the 0xFFFF+CFE_MSG_SIZE_OFFSET+1 rejection case that called CFE_MSG_Init on `cmd` (a bare CFE_MSG_CommandHeader_t) - that size is now accepted by Init, and a memset of that size into `cmd` would run well past it. Kept the underflow case and the largest-representable-size acceptance case (CFE_MSG_Init on the pre-existing static `maxmsg` union already sized to sizeof(uint8[0xFFFF + CFE_MSG_SIZE_OFFSET])), which still exercises CFE_MSG_SetSize's own upper-bound branch end-to-end. Verification (WSL, nasa/cfs-ut bundle, cfe swapped to this branch, SIMULATION=native ENABLE_UNIT_TESTS=true, -j2): - coverage-msg-ALL: 618/618 PASS (was 619/619 before removing the one assertion), cfe_msg_init.c gcov: Lines 100.00% of 13, Branches 100.00% of 8. - Functional test (core-cpu1 + cfe_testcase loaded via ES_StartApp, matching functional-tests.yml): sb_sendrecv_test.c:446-447 pass before AND after this change (CFE_MSG_Init == CFE_SUCCESS, CFE_SB_TransmitBuffer == CFE_SB_MSG_TOO_BIG), overall SUMMARY TOTAL::2242 PASS::1867 FAIL::0 MIR::13 identical in both runs - this harness did not reproduce the CI regression described for run 33416261229 (that run is also dated 2026-08-31, before this branch's own 4e2c757 commit date of 2026-09-05). Flagged for Phil; the code change stands on the SetSize-duplication/design argument above independent of that specific reproduction. Findings 2 and 3 of nasa#2745 remain out of scope, per 4e2c757: the priext initializer was fixed by 13ed881 (nasa#2317), and the checksum walk needs a caller-provided bound, which is an API decision. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HDRvC9ePDP3i6xpxFAECFg
|
Hey @dzbaker 👋 following up on the workflow failures: they were on the earlier head (5e83079), where The current head (4e2c757, the one @sylvesterkaczmarek approved) bounds Init by the CCSDS length field instead ( The nine workflows for 4e2c757 have been sitting in "approve and run" since Sept 5, so the checks shown are still the old head's. Could you kick them off when you get a sec? 🙏⚡ Edit: two more commits landed after this note (18b701d, then its revert 0c3790c), the tree at the head is identical to 4e2c757. The intermediate commit came from a background job of mine that dropped the CCSDS upper bound in Init; I reverted it because that reintroduces the oversize memset before SetSize can reject the length. Sorry for the noise, nothing changed against what was approved. |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
Rechecked current 0c3790cc. Its tree is identical to the previously approved 4e2c757d (fe1ebb26579b in both cases); the intervening change was fully reverted. The scoped #2745 fixes and boundary coverage are therefore unchanged. No blocker from me.
|
Heyy @sylvesterkaczmarek im actually working here on improving my agentic setup, Lestarch just recently setup a really cool bot himself for checking all the issues in code, in order to offload and mitigate bugs and mistakes, so I got inspired and am re-reviewing my work ✨🙌 |
|
Quick update: my Individual CLA for the cFS framework went to GSFC-SoftwareRelease on 2026-09-16, after this PR was opened, so I've ticked that box in the checklist. Happy to adjust anything if needed. |
Checklist (Please check before submitting)
Describe the contribution
Fixes #2745, findings 1 and 4 only (scope narrowed per review):
CFE_MSG_Init: the caller-suppliedSizeis now validated before thememset, with the same boundCFE_MSG_SetSizeuses (CFE_MSG_SIZE_OFFSET <= Size <= 0xFFFF + CFE_MSG_SIZE_OFFSET);CFE_MSG_SIZE_OFFSETmoved tocfe_msg_priv.hso both share it.GetSystem/GetSize:|instead of+for byte concatenation.Finding 2 (priext initializer) was already fixed upstream in 13ed881 (#2317). Finding 3 (checksum walk) needs a decision on the BufLen API and is left out of this PR.
Testing performed
test_cfe_msg_init.cadds an oversize case (a 65 KB buffer,Sizeone over the bound) and an underflow case (SizebelowCFE_MSG_SIZE_OFFSET), both expectingCFE_MSG_BAD_ARGUMENT, plus the exact-bound case. Run locally in the cFS dev bundle with the tests kept andcfe_msg_init.creverted to dev: coverage-msg-ALL dies with a SegFault in Test_MSG_Init (the oversize memset runs past the message). With the fix, coverage-msg-ALL passes.Expected behavior changes
Malformed message inputs that previously caused OOB reads/writes now return an error. Bit-field concatenation in
GetSystem/GetSizeis now correct for fields with overlapping bits.System(s) tested on
Hardware: x86_64 (WSL2), OS: Ubuntu 22.04, Versions: cFE dev 2612eb0 with OSAL and PSP from the cFS dev bundle, native build with ENABLE_UNIT_TESTS
Contributor Info
Filip Koscak - phil.phaulre@gmail.com