fix(incoming): treat GRANT offset as unsigned in homa_grant_pkt - #99
Open
randomizedcoder wants to merge 1 commit into
Open
randomizedcoder wants to merge 1 commit into
randomizedcoder wants to merge 1 commit into
Conversation
A GRANT packet's offset is an unsigned 32-bit wire field, but
homa_grant_pkt() reads it into a signed int:
int new_offset = ntohl(h->offset);
An offset with the top bit set (>= 2GB) becomes negative, so
`new_offset > rpc->msgout.granted` is false and the grant is silently
dropped instead of being bounded. Read it as u32.
Clamp before the assignment, in unsigned space, so the oversized value
never lands in the signed rpc->msgout.granted (int) even transiently:
rpc->msgout.granted = min_t(u32, new_offset, rpc->msgout.length);
The result is always <= msgout.length, so the store into the signed
field is well-defined, and grants are capped at the message length as
before.
Adds a table-driven test, homa_grant_pkt__offset_is_unsigned: the
high-bit row advances granted to the message length (20000) after the
fix, versus being ignored (granted stays 5000) before it. The normal and
past-end rows match the existing __basics / __grant_past_end_of_message
behavior; the incoming suite stays green (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.
Bug: GRANT offset read as signed in
homa_grant_pkt()ntohl()yields an unsigned 32-bit value, butnew_offsetis a signedint. An offset with the top bit set (≥ 2 GB) becomes negative, sonew_offset > rpc->msgout.grantedis false and the grant is silently dropped — the clamp-to-length path that was written to bound oversized grants never runs.Fix
Read the wire offset as
u32, and clamp before assigning into the signedrpc->msgout.granted(anint) so an oversized value never lands in the signed field even transiently:The
min_t(u32, …)result is always ≤msgout.length, so the store into the signed field is well-defined, and grants remain capped at the message length.min_t(u32, …)matches existing idiom inhoma_outgoing.c.Verification (TDD, red → green)
Table-driven test
homa_grant_pkt__offset_is_unsigned, on a 20000-byte outgoing message withgrantedpre-set to 5000:The normal/past-end rows reproduce the existing
homa_grant_pkt__basics(12000) andhoma_grant_pkt__grant_past_end_of_message(25000→20000) behavior. Built and run against thetest/kselftest harness (ASan on).Uses the table-driven test style proposed in the first PR of this series.