nstun: preserve bounds in selected network buffer paths with std::span - #333
Open
YuvalFradkin1 wants to merge 1 commit into
Open
YuvalFradkin1 wants to merge 1 commit into
YuvalFradkin1 wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
YuvalFradkin1
force-pushed
the
nstun-span-hardening
branch
from
September 11, 2026 12:20
39bbf03 to
786fc0b
Compare
This branch has not been deployed
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.
nstun: preserve bounds in selected network buffer paths with std::span
Summary
This change replaces selected raw pointer-and-length interfaces in the nstun network stack with bounds-carrying C++ types. The goal is to preserve buffer-size information across the affected call chains and reduce reliance on raw pointer arithmetic in network-facing parsing and packet-construction code.
This is a hardening change. It does not claim to remediate a known exploitable vulnerability.
Threat model and invariant
nstun processes bytes received from network peers and proxy endpoints. The relevant security invariant is that every buffer sub-region used by the changed paths retains an explicit, valid bound from its creation through its use.
Before this change, several selected paths represented a buffer as a raw pointer plus a separately managed size or derived sub-region. After this change, those paths use
std::spanorstd::arrayso that the intended bounds are explicit at the interface boundary and preserved when deriving sub-regions.Changes
net_defs.hcompute_checksum_part()to acceptstd::span<const uint8_t>.first()andsubspan()for bounded iteration and incremental checksum processing.void*/size_tcompatibility overload for call sites outside this change.tcp.cctcp_build_options()to acceptstd::span<uint8_t>.std::spanand derive header/payload regions withsubspan()rather than pointer-plus-offset expressions.std::array<uint8_t, IPV6_ADDR_LEN>.Validation
Built and analyzed on Linux with clang 18 using:
Actionable
tcp.ccunsafe-buffer-usage warnings were reduced from 31 to 25.nstun_ip_testpasses against the updated checksum interface.Checksum behavior was verified against a reference implementation for empty, odd-length, 20-byte, and 40-byte inputs, including incremental chaining, for eight test cases in total.
Scope and non-goals
This change is intentionally limited to the selected checksum, TCP option, frame-buffer, receive-buffer, and IPv6-address paths.
It does not migrate the
proxy_rx_bufferpaths or unrelated nstun files. Those paths require separate invariant mapping and validation and should be handled in a follow-up change rather than expanding this review.