Leadaxe:说明 WireGuard UDP GSO 回退的首包异常及验证范围
Leadaxe 说明,无 detour 的 WireGuard / AmneziaWG 端点在网卡缺少硬件发送校验和、内核以 EIO 拒绝 UDP GSO,且套接字首次发送包含多个数据报时,回退代码残留的缓冲区列表可能把后续报文拼到首包尾部,使首包无法解密。他表示修复会重建每条消息的缓冲区列表;问题据代码定位并由重填单测覆盖,尚未在缺少校验和卸载的硬件上完成端到端复现。
作者原文@LeadaxeSymptom
On a WireGuard / AmneziaWG endpoint without
detour, the first batch sent after the socket is opened can lose its first datagram when the kernel refuses UDP segmentation offload (UDP GSO). The datagram is not dropped locally: it goes out with the following datagrams of the batch glued to its tail, and the peer discards it because it does not decrypt. The rest of the batch arrives correctly.Nothing is logged for the lost datagram itself. The only visible trace is the existing one-time message about UDP GSO being disabled on the socket.
When it happens
All three at once:
- the NIC has no hardware TX checksumming, so the kernel answers a
UDP_SEGMENTsend withEIO;- it is the first send on that socket (after the failure offload is turned off until the socket is reopened);
- that send carries more than one datagram. Tunnel data goes out one packet per call, so in practice this is an AmneziaWG handshake burst with junk packets (
Jc) andi1–i5.So it is one datagram per socket lifetime, usually a junk packet in front of the handshake. The tunnel still comes up, which is why this went unnoticed.
Cause
The code is in the socket bind of wireguard-go (
conn/bind_std.go,StdNetBind.Send), which sing-box-lx takes from its fork ofsagernet/wireguard-go.
coalesceMessagespacks several datagrams into one message for the kernel to segment. Upstream commitfcbb7c4("Coalesce UDP GSO segments as iovecs", 2026-07-06) changed how: instead of copying the following datagrams into the spare capacity of the first buffer, it appends them to the message as additional buffers (iovecs). The message then holds a list: first, second, third.The fallback next to it was not adapted. When the send fails with
EIO,Sendturns offload off and fills the same message set again, one datagram per message:(*msgs)[i].Addr = ua (*msgs)[i].Buffers[0] = bufs[i][offset:] setSrcControl(&(*msgs)[i].OOB, standardEndpoint)It assigns only
Buffers[0]. A message that was coalesced into on the failed attempt still lists the other segments inBuffers[1:], andsendmmsgwrites all of them as one datagram.Fix
The retry now replaces the buffer list of the message instead of assigning its first element (
setMessageBufferinconn/lx_messages.go), with a test that coalesces three datagrams into a message and then fills the set the way the retry does.
- fork: Leadaxe/wireguard-go-awg2-lx#7, commit Leadaxe/wireguard-go-awg2-lx@34269a2 (the same commit that stops the bind from resetting all 128 prepared messages after every datagram);
- core: submodule bump in d0c4b1716;
- ships in
v1.14.4-lx.36.Background and measurements are in SPEC 160 §2.1; the entry in the registry of fixes carried over upstream is in FEATURE 004.
How it was found, and what is not verified
I found it by reading the code while changing the message cleanup right next to it. I did not reproduce it on hardware: the test board has working GSO, so the
EIOpath cannot be triggered there. The fix is covered by a unit test of the refill, not by an end-to-end run on a NIC without checksum offload.Upstream
sagernet/wireguard-gostill has the original line as offcbb7c4; the fix is to be dropped from the fork when upstream changes the fallback itself.