fix(outgoing): keep homa_tx_skb_alloc frag length arithmetic signed - #98
Open
randomizedcoder wants to merge 1 commit into
Open
randomizedcoder wants to merge 1 commit into
randomizedcoder wants to merge 1 commit into
Conversation
In homa_tx_skb_alloc() the per-frag length is computed as:
frag_bytes = min(skb_frag_size(msg_frag) - bytes_to_skip, bytes_left);
skb_frag_size() is unsigned, so the first argument is unsigned while
bytes_left (and the frag_bytes result) are int -- a mixed-sign min(). The
skip loop guarantees bytes_to_skip < skb_frag_size() today, so the value
is correct; but should that invariant ever break, the unsigned subtraction
would wrap to a huge positive length and the mixed-sign comparison would
happily pick it. Compute the available bytes as a signed int first, so
min() compares two ints and an underflow stays negative (and loses the
min).
Pure refactor of the arithmetic's type; no behavior change. The
homa_outgoing unit suite stays green (52/52), including all the
homa_tx_skb_alloc frag offset/size checks.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Signedness: mixed-sign
min()inhoma_tx_skb_alloc()The per-fragment copy length is:
skb_frag_size()returnsunsigned int, soskb_frag_size(msg_frag) - bytes_to_skipis unsigned, whilebytes_leftand thefrag_bytesresult areint— a mixed-signmin().The skip loop just above guarantees
bytes_to_skip < skb_frag_size(msg_frag), so on current builds the value is always correct — this is a robustness / consistency fix, not a live miscompile. But the shape is fragile: if that invariant ever broke, the unsigned subtraction would wrap to a huge positive length and the mixed-sign comparison would select it as the "minimum".Fix
Frag sizes are page-scale (≤ 64 KB), well within
int, so the cast is safe.Verification (regression)
No behavior change on current compilers, so the gate is the existing behavioral suite: the
homa_outgoingunit tests stay green (52/52), including everyhoma_tx_skb_alloc__*case that checks fragment offsets and sizes.This one is a defensive/readability change — happy to drop it if you'd rather leave the line as-is.