[PR #169] device: rebase transport padding after TUN read #181

Open
opened 2026-10-13 21:04:20 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amneziawg-go/pull/169
Author: @coremraz
Created: 8/1/2026
Status: 🔄 Open

Base: master ← Head: fix/s4-startup-race


📝 Commits (1)

  • 60b7f38 device: rebase transport padding after TUN read

📊 Changes

3 files changed (+164 additions, -4 deletions)

View changed files

➕ device/s4_startup_race_test.go (+135 -0)
📝 device/send.go (+22 -3)
📝 device/uapi.go (+7 -1)

📄 Description

Fixes #168.

Problem

RoutineReadFromTUN captured the transport padding (S4) before a blocking
TUN read. If a UAPI update changed S4 while that read was blocked, the
outbound element retained the old offset while the receiving device classified
the datagram using the new offset. The first transport packet could then be
discarded as an unknown type after a successful handshake.

Change

  • Re-read S4 after Read returns. If it changed, move the TUN payload to the
    current offset before IP classification and rebuild the outbound packet
    slice, preserving the in-place AEAD Seal layout.
  • Drop only a packet that no longer fits after the new offset is applied.
  • Reject S1-S4 values that leave no byte for TUN payload, before mutating
    device state.
  • Add a gated regression test that deterministically changes S4 while the
    first TUN read is blocked, plus padding boundary and rejection-atomicity
    coverage.

Validation

All commands ran in golang:1.25.12 on Linux with CAP_NET_ADMIN and
/dev/net/tun:

  • The new gated test fails 10/10 on cf9d2dd without this change.
  • Gated regression and padding-bound tests pass 10/10 with -race.
  • go test ./device -run '^TestAWGDevicePing$' -count=10 -race=false passes.
  • go test ./device -run '^TestAWGDevicePing$' -count=10 -race passes.
  • go build ./... passes.

go vet ./... still reports a pre-existing copylocks warning in
device/pools_test.go:67, outside this change.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/amnezia-vpn/amneziawg-go/pull/169 **Author:** [@coremraz](https://github.com/coremraz) **Created:** 8/1/2026 **Status:** 🔄 Open **Base:** `master` ← **Head:** `fix/s4-startup-race` --- ### 📝 Commits (1) - [`60b7f38`](https://github.com/amnezia-vpn/amneziawg-go/commit/60b7f38aa1e3fbb99124894ad4194ecf9b0496d5) device: rebase transport padding after TUN read ### 📊 Changes **3 files changed** (+164 additions, -4 deletions) <details> <summary>View changed files</summary> ➕ `device/s4_startup_race_test.go` (+135 -0) 📝 `device/send.go` (+22 -3) 📝 `device/uapi.go` (+7 -1) </details> ### 📄 Description Fixes #168. ## Problem `RoutineReadFromTUN` captured the transport padding (S4) before a blocking TUN read. If a UAPI update changed S4 while that read was blocked, the outbound element retained the old offset while the receiving device classified the datagram using the new offset. The first transport packet could then be discarded as an unknown type after a successful handshake. ## Change - Re-read S4 after `Read` returns. If it changed, move the TUN payload to the current offset before IP classification and rebuild the outbound packet slice, preserving the in-place AEAD `Seal` layout. - Drop only a packet that no longer fits after the new offset is applied. - Reject S1-S4 values that leave no byte for TUN payload, before mutating device state. - Add a gated regression test that deterministically changes S4 while the first TUN read is blocked, plus padding boundary and rejection-atomicity coverage. ## Validation All commands ran in `golang:1.25.12` on Linux with `CAP_NET_ADMIN` and `/dev/net/tun`: - The new gated test fails 10/10 on `cf9d2dd` without this change. - Gated regression and padding-bound tests pass 10/10 with `-race`. - `go test ./device -run '^TestAWGDevicePing$' -count=10 -race=false` passes. - `go test ./device -run '^TestAWGDevicePing$' -count=10 -race` passes. - `go build ./...` passes. `go vet ./...` still reports a pre-existing copylocks warning in `device/pools_test.go:67`, outside this change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
amnezia-vpn/amneziawg-go#181
No description provided.