harden(incoming): read DATA seg.offset as u32 in homa_copy_to_user - #100
Open
randomizedcoder wants to merge 1 commit into
Open
randomizedcoder wants to merge 1 commit into
randomizedcoder wants to merge 1 commit into
Conversation
homa_copy_to_user() reads the DATA segment offset into a signed int:
int offset = ntohl(h->seg.offset);
The offset is an unsigned wire field, so for consistency with
homa_add_packet() (which already uses `u32 start = ntohl(h->seg.offset)`)
read it as u32 here too.
Note: this is a defense-in-depth / type-consistency change, not a live
bug. Packets only reach homa_copy_to_user() after homa_add_packet() has
validated the offset as u32 and dropped anything with
start >= rpc->msgin.length; msgin.length is itself capped at
HOMA_MAX_MESSAGE_LENGTH (1,000,000) by homa_message_in_init(). So offsets
that reach the copy-out path are always small and non-negative -- the old
`int` was safe in practice. start_offset/end_offset and offset+copied are
unaffected (values stay well within int range).
Adds a characterization test, homa_data_pkt__seg_offset_is_unsigned,
covering the sign-boundary offset 0x80000000: it is dropped as
PKT_TOO_BIG and never queued (green before and after -- it locks in the
existing guarantee at the signed/unsigned boundary, complementing the
existing offset-2000000 case). Incoming suite: 123/123.
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.
Hardening: read DATA
seg.offsetasu32inhoma_copy_to_user()The DATA segment offset is an unsigned wire field.
homa_add_packet()already reads it asu32 start = ntohl(h->seg.offset); this makes the copy-out path consistent.I want to be upfront: there is no reachable failure here today. A packet only reaches
homa_copy_to_user()afterhoma_add_packet()has already validated its offset (asu32) and dropped anything withstart >= rpc->msgin.length:and
rpc->msgin.lengthis itself capped atHOMA_MAX_MESSAGE_LENGTH(1,000,000) byhoma_message_in_init(). So offsets that reach the copy-out loop are always small and non-negative — the originalintwas safe. This change is type-consistency / defense-in-depth only.start_offset,end_offset, andoffset + copiedare unaffected (values stay well withinint).Fix
Verification
Adds
homa_data_pkt__seg_offset_is_unsigned, exercising the signed/unsigned boundary offset0x80000000: it is dropped asPKT_TOO_BIGand never queued. This is a characterization test — it's green before and after — that locks in the existing guarantee at the sign boundary, complementing the existingoffset = 2000000case inhoma_data_pkt__homa_add_packet_returns_error.This one is optional hardening — the original static-analysis finding turned out to be already mitigated upstream of this line; happy to close it if you'd rather not carry the change.