fix: drop malformed TUN packets#132
Closed
tionis wants to merge 1 commit into
Closed
Conversation
Traffic control parsed packets from the full message buffer and trusted the packet's advertised length. On Windows this could panic when the TUN read returned fewer bytes than an IPv6 payload length claimed, for example slicing 2050 bytes from a 2016-byte read. Carry the actual TUN read length into TCElement.Packet, make ParsePacket reject packets whose advertised length exceeds the available bytes, and drop malformed packets instead of panicking.
There was a problem hiding this comment.
Pull request overview
This PR hardens the traffic-control (TC) pipeline against malformed packets by ensuring packet parsing is bounded by the actual TUN read size and by rejecting packets whose advertised length exceeds available bytes, preventing slice panics (notably on Windows).
Changes:
- Change
TCElement.ParsePacketto returnbooland reject packets whose advertised length exceeds the available bytes. - Carry the actual TUN read length into
TCElement.PacketduringRoutineReadFromTUN. - Add unit tests covering oversized advertised lengths and trimming to the advertised length.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| polyamide/device/traffic_manip.go | Makes packet parsing bounded and failure-aware (bool), adds header-length checks helper. |
| polyamide/device/traffic_manip_test.go | Adds tests to verify oversized packets are rejected and valid packets are trimmed. |
| polyamide/device/traffic_control.go | Drops malformed packets when ParsePacket fails (in addition to Validate). |
| polyamide/device/send.go | Sets TCElement.Packet to the actual bytes read from TUN (bounded by sizes[i]). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
36
to
+40
| l := elem.GetLength() | ||
| elem.Packet = elem.Buffer[MessageTransportHeaderSize : MessageTransportHeaderSize+l] | ||
| if int(l) > len(elem.Packet) { | ||
| return false | ||
| } | ||
| elem.Packet = elem.Packet[:l] |
Contributor
Author
|
I'm closing this to instead open a PR that combines all the small windows fixes I added. |
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.
Traffic control parsed packets from the full message buffer and trusted the packet's advertised length. On Windows this could panic when the TUN read returned fewer bytes than an IPv6 payload length claimed, for example slicing 2050 bytes from a 2016-byte read.
Carry the actual TUN read length into TCElement.Packet, make ParsePacket reject packets whose advertised length exceeds the available bytes, and drop malformed packets instead of panicking.