Repository navigation
fix: populate response TTL on macOS/BSD IPv4 (1-byte IP_RECVTTL cmsg) - #117
Merged
Merged
Conversation
The cmsg length gate added when hardening the unsafe cmsg parser required CMSG_LEN(size_of::<c_int>()). That is right for Linux IPv4 IP_TTL and the IPv6 hop-limit (both arrive as a 4-byte int), but the BSDs and macOS deliver the IPv4 IP_RECVTTL value as a single u_char. Its cmsg is CMSG_LEN(1), which fell under the gate and was dropped, so response_ttl came back None and the return-hop / path-asymmetry estimate derived from it went blank on those platforms. Read the value width-aware: require at least one data byte, read a 4-byte int when the payload is >= 4 bytes, otherwise the single byte. This keeps the short-cmsg over-read protection while restoring the 1-byte case. Adds a regression test that feeds a synthetic 1-byte and 4-byte cmsg (the 1-byte case returned None before, Some after) and covers the empty-payload skip; it runs the platform-specific cmsg_type branches under their real cfg on the macOS and FreeBSD CI runners.
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.
Problem
The unsafe cmsg-parsing hardening added a length gate of
CMSG_LEN(size_of::<c_int>())before reading the TTL/hop-limit out of a control message. That is correct for:IP_TTL— delivered as a 4-byteintintper RFC 3542But the BSDs and macOS deliver the IPv4
IP_RECVTTLvalue as a singleu_char. Its control message isCMSG_LEN(1), which is below the 4-byte gate, so it was skipped andresponse_ttlcame backNone. That blanks the return-path-hop / path-asymmetry estimate (record_response_ttl→estimate_return_hops) on macOS/FreeBSD/NetBSD IPv4.The pre-hardening code happened to work only via a technically-UB 3-byte over-read of the control buffer; the hardening correctly removed the over-read but dropped the valid 1-byte case with it.
Fix
Read the value width-aware: gate on at least one data byte, read a 4-byte
intwhen the payload is>= 4bytes, otherwise read the single byte. The short-cmsg over-read protection is preserved.Testing
cmsg_typebranches under their realcfgon the macOS and FreeBSD CI runners.cargo fmt,cargo clippy --all-targets -- -D warnings, and the full test suite pass locally.