Repository navigation
nstun: validate UDP reply peers - #316
Merged
robertswiecki merged 1 commit intoOct 2, 2026
Merged
robertswiecki merged 1 commit into
robertswiecki merged 1 commit into
Conversation
Contributor
Author
|
Hey could you please review this! |
Collaborator
|
Thank you! |
zerox80
pushed a commit
to zerox80/nsjail
that referenced
this pull request
Oct 16, 2026
…-reply-peer-validation nstun: validate UDP reply peers
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.
Summary
Validate the sender of host-side UDP datagrams before forwarding them into an nstun guest flow.
Outbound UDP flows use unconnected host UDP sockets. Previously,
handle_host_udp()accepted every datagram delivered to that socket and forwarded it into the guest without checking that the sender matched the flow's upstream peer. If an unexpected sender can reach or learn the ephemeral host UDP port, it can inject data into that guest flow. For redirected and SOCKS5 flows, the reply path can also present forwarded data using the flow's original destination as the apparent source.This change adds a small peer predicate and drops datagrams whose address/port do not match the flow's expected peer:
BND.ADDR/BND.PORT).Validation
make -j2: PASStests/nstun_udp_peer_test: PASS, covering IPv4, IPv6, redirect, wrong-address/wrong-port, and SOCKS5 relay casesnstun_buffer_budget_test,nstun_policy_test, andnstun_ip_test: PASSgit diff --check: PASSFull
make testpasses the command-line and all nstun unit tests, then stops at the first namespace sanity test because this host denies writing/proc/<pid>/setgroups. That environment limitation occurs after the changed nstun paths have passed their tests.