fix(proto): canonicalize FourTuple's remote/local_ip at construction (noq#738) - #784
Open
cuzic wants to merge 4 commits into
Open
fix(proto): canonicalize FourTuple's remote/local_ip at construction (noq#738)#784cuzic wants to merge 4 commits into
cuzic wants to merge 4 commits into
Conversation
…(noq#738) Alternative to patching each individual == / != comparison site (early_discard_packet's local_ip check in 4bae6ed, its remote check in fix/noq-738-remote-canonicalize): canonicalizing once in FourTuple::new() fixes every downstream comparison for free, including ones that were still broken after both of the above -- notably Endpoint's HashMap<FourTuple, ConnectionHandle> connection-routing table, which hashes/compares FourTuple's derived Hash/Eq directly, plus several other == / != .remote comparisons in Connection (is_probably_same_path, PATH_CHALLENGE on-path detection, OBSERVED_ADDRESS path matching, peer migration detection) that all have the same latent bug.
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.
Closes #738. Alternative to #783 — see that PR for the minimal one-line fix;
this one takes a broader approach to the same root cause.
Problem
4bae6edd(the hotfix posted in #738) and #783 both patch individual==/!=comparison sites inConnection::early_discard_packettocanonicalize IPv4-mapped-IPv6 addresses (
::ffff:a.b.c.d) beforecomparing, since dual-stack sockets can report the same peer in either
form depending on the code path (observed on Android when a
physical-interface-bound socket is handed to noq via an abstract socket).
Patching comparisons one at a time only closes the specific sites someone
has actually hit a bug in.
FourTuplederivesPartialEq/Eq/Hash,and it's used directly (not just via the two
early_discard_packetsites)in:
Endpoint'sHashMap<FourTuple, ConnectionHandle>connection-routingtable
Connection::is_probably_same_pathEvery one of these has the same latent bug: two
FourTuples that are"the same address" from the OS's perspective but differ in
mapped-vs-plain representation will compare unequal.
Fix
Canonicalize
remoteandlocal_iponce, inFourTuple::new()itself,so every downstream comparison/hash sees one canonical representation
regardless of which form the OS happened to report a given datagram's
address in. This makes the two
early_discard_packet-specific patches(
4bae6edd, #783) unnecessary — they're subsumed by this fix — thougheither could still land independently since they're harmless on their
own.
Not claiming this is strictly the better fix — a single well-placed
comparison-time fix (#783) is simpler to reason about and reviews faster.
Filing both so the maintainers can pick.
Testing
Same regression test and full-suite run as #783 (this PR includes the
same test-adaptation commit, since both branches were cut from
4bae6eddindependently):
noq-proto/src/tests/multipath.rs::open_path_with_explicit_local_ip(from the
noq-738branch) passes; fails on unpatchedmain.cargo test -p noq-proto: 388 passed, 0 failed.Secondaryestablished, then
PhysicalWifi/PhysicalCellularboth validate onthe first attempt: