net: preserve checksum state for empty fragments - #20058
Merged
xiaoxiang781216 merged 1 commit intoSep 5, 2026
Merged
Conversation
checksum() accesses data[0] and calculates an invalid last_byte pointer when processing an empty fragment with odd state set. Return early when len is zero to preserve the checksum state and avoid accessing data from an empty fragment. Assisted by: GitHub Copilot Signed-off-by: Megha Rajput <i.meghar.2408@gmail.com>
xiaoxiang781216
approved these changes
Sep 4, 2026
acassis
approved these changes
Sep 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
checksum() accesses data[0] and calculates an invalid last_byte pointer when processing an empty fragment with odd state set.
Return early when len is zero to preserve the checksum state and avoid accessing data from an empty fragment.
Assisted by: GitHub Copilot
Summary
checksum()innet/utils/net_chksum.cmishandles a zero-length fragmentwhen an odd byte is still pending from a previous fragment (
*odd == true).Before this fix, the function unconditionally computed:
and, when
*odd == true, unconditionally readdataptr[0]to consume thepending byte, regardless of whether the current fragment contained any bytes.
With
len == 0, this could form an invalid pointer from the zero-lengthfragment and read
data[0]even though the current fragment contained novalid bytes. The code also cleared
*odd, discarding the pending-byte stateneeded by the next fragment.
This can corrupt the checksum when a byte stream is split such that an
empty I/O buffer fragment follows an odd-length fragment.
The fix adds an early return for
len == 0, before any pointer arithmetic ordereference.
sumand*oddare left unchanged, so a zero-length fragmentdoes not affect the running checksum state.
Fixes #20010
Impact
This prevents an invalid read and checksum corruption when an empty fragment
is encountered while an odd byte is pending.
No API or ABI changes are introduced.
Validation
The corresponding regression test is provided in
apache/nuttx-apps PR apache/nuttx-apps#3771
Regression test with the buggy implementation
The corresponding regression test was verified against the implementation
without the zero-length guard and failed as expected:
Regression test with the fix applied
With the
len == 0handling fix restored, the test passed:The
mount failed: 20message occurs during simulator startup and did notprevent
cmocka_net_othersfrom running successfully.git diff --checkcompleted with no output../tools/checkpatch.sh -g HEADcompleted successfully with all checks passing.Checkpatch
The exact CI-style check was run: