Skip to content

net/packet: enforce packet bounds and validate subprotocol offsets - #21634

Open
1kailas wants to merge 2 commits into
tailscale:mainfrom
1kailas:net-packet-bounds
Open

1kailas wants to merge 2 commits into
tailscale:mainfrom
1kailas:net-packet-bounds

Conversation

@1kailas

@1kailas 1kailas commented Oct 2, 2026

Copy link
Copy Markdown

When decoding IPv4 and IPv6 packets, trailing bytes in the underlying buffer beyond the packet's declared total length could be included in the subprotocol slice. In cases where the buffer was larger than the IP packet (e.g. Ethernet frame padding or fixed-size receive buffers), fields and ports could be decoded from bytes outside the IP datagram.

This change:

  • Rejects IPv4 packets with an invalid IHL (< 5 / 20 bytes), which could otherwise leave subofs pointing inside the IPv4 header.
  • Clamps sub to q.length in both decode4 and decode6.
  • Validates that the IPv6 fragment extension header fits within q.length rather than len(b).
  • Ensures TCP data offset is at least tcpHeaderLength and fits within the packet.
  • Bounds Parsed.Transport() to p.length to avoid leaking trailing buffer bytes, mirroring Parsed.Payload().
  • Uses invoking.subofs directly for the IPv4 header length in GenerateICMPHostUnreachable.

Updates #cleanup

When decoding IPv4 and IPv6 packets, trailing bytes in the underlying
buffer beyond the packet's declared total length could be included in the
subprotocol slice. In cases where the buffer was larger than the IP
packet (e.g. Ethernet frame padding or fixed-size receive buffers),
fields and ports could be decoded from bytes outside the IP datagram.

Additionally:
- Reject IPv4 packets with an invalid IHL (< 5 / 20 bytes), which could
  otherwise leave subofs pointing inside the IPv4 header.
- Clamp sub to q.length in both decode4 and decode6.
- Validate that the IPv6 fragment extension header fits within q.length
  rather than len(b).
- Ensure TCP data offset is at least tcpHeaderLength and fits within the
  packet.
- Bound Parsed.Transport() to p.length to avoid leaking trailing buffer
  bytes, mirroring Parsed.Payload().
- In GenerateICMPHostUnreachable, use invoking.subofs directly for the
  IPv4 header length.

Updates #cleanup

Change-Id: I598018faebf5f8d6884e19753186176ff363732c
Signed-off-by: Kailasnath T <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 14:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants