mirror of
https://github.com/amnezia-vpn/amneziawg-go.git
synced 2026-12-03 18:42:09 +07:00
[PR #208] fix: make I1-I5 safe to change while handshakes are sent #206
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
amnezia-vpn/amneziawg-go#206
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/amnezia-vpn/amneziawg-go/pull/208
Author: @Dv2Corn
Created: 11/5/2026
Status: 🔄 Open
Base:
master← Head:fix/ipackets-race📝 Commits (1)
6e83005fix: make I1-I5 safe to change while handshakes are sent📊 Changes
4 files changed (+56 additions, -10 deletions)
View changed files
📝
device/device.go(+1 -1)📝
device/device_test.go(+46 -0)📝
device/send.go(+2 -2)📝
device/uapi.go(+7 -7)📄 Description
Device.ipacketsis a plain[5]*obfChain(device/device.go#L113).IpcSetassigns it on everyi1=..i5=line (device/uapi.go#L438-L471) holding onlyipcMutex, while every handshake initiation reads it with no lock at all (device/send.go#L139), from the TUN reader (device/send.go#L439) and the handshake timers (device/timers.go#L108, L126). AnyIpcSeton a running device that carries aniN=line, including a tool re-sending its full config to add or remove a peer, is therefore a data race. The race detector reports it as a write inhandleDeviceLineagainst a read inSendHandshakeInitiation. Every other device-level valueIpcSetwrites is already atomic or under a lock (junk, S1-S4, H1-H4, timings, header protection key).[5]atomic.Pointer[obfChain]:IpcSetstores,SendHandshakeInitiationandIpcGetload. AnobfChainis never modified afternewObfChainreturns, so publishing the pointer atomically is enough. A handshake that races with an update uses either the old or the new chain for each slot.TestSignaturePacketsChangeDuringHandshaketodevice/device_test.go: one goroutine keeps sending handshake initiations while I1 is set, changed and cleared throughIpcSet, and the test checks that the cleared value is gone fromIpcGet. With-raceit fails on master (WARNING: DATA RACE, write atuapi.go:443, read atsend.go:139) and passes 200 of 200 runs with this change.Tested with Go 1.27.3:
go test -race -count=200 -run TestSignaturePacketsChangeDuringHandshake ./deviceandgo test ./....TestAWGDevicePingfails the same way with and without this change in my environment, andTest_outlineIntegrationneeds network access, which my test environment did not have.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.