snapshot: sagernet/gvisor v0.0.0-20260727.0-sing-box-mod.1 + SPEC 048 guard

Обновление снапшота с v0.0.0-20250811.0 на пин, которого требует
sing-box после мержа 235 коммитов (upstream d620bbbf2 "Update gvisor to
20260727.0"). Прежний снапшот был взят 2026-08-04 ровно с той версии,
на которой тогда стоял апстрим; разрыв возник 2026-08-05 вместе с его
бампом.

За год апстрим-gvisor изменил ~14 000 строк в 292 файлах. Значимое для
нас — сетевой стек: tcp/connect.go (PMTU-discovery + исправление
начального RTT/RTO: раньше задержка ACK внутри стека завышала стартовый
таймаут на несколько RTT), tcp/snd.go, tcp/rcv.go, stack/conntrack.go,
stack/packet_buffer.go. Всего 30 файлов в TCP и 37 в stack.

Баг SPEC 048 апстрим НЕ исправил — проверено по коду новой версии:
handleConnecting по-прежнему проверяет состояние endpoint'а, но не ep.h,
а performHandshake так же зануляет h и отпускает мьютекс до Close().
Поэтому guard перенесён (12 строк) вместе со своим тестом (45 строк).

Red/green проверен на новой базе: без guard'а тест падает с той же
nil-паникой, что в полевом крашдампе; с ним зелёный.
This commit is contained in:
Leadaxe 2026-08-05 14:53:31 +03:00
parent ffebe42860
commit 117243aa02
293 changed files with 16413 additions and 2842 deletions

View file

@ -17,7 +17,6 @@ package tun
import (
"fmt"
"github.com/sagernet/gvisor/pkg/atomicbitops"
"github.com/sagernet/gvisor/pkg/buffer"
"github.com/sagernet/gvisor/pkg/context"
"github.com/sagernet/gvisor/pkg/errors/linuxerr"
@ -258,10 +257,15 @@ func (d *Device) Write(data *buffer.View) (int64, error) {
case d.flags.TUN:
// TUN interface with IFF_NO_PI enabled, thus
// we need to determine protocol from version field
if data.Size() == 0 {
// Ignore bad packet.
return dataLen, nil
}
version := data.AsSlice()[0] >> 4
if version == 4 {
switch version {
case 4:
protocol = header.IPv4ProtocolNumber
} else if version == 6 {
case 6:
protocol = header.IPv6ProtocolNumber
}
}
@ -362,22 +366,26 @@ type tunEndpoint struct {
tunEndpointRefs
*channel.Endpoint
stack *stack.Stack
nicID tcpip.NICID
name string
isTap bool
persistent atomicbitops.Bool
closed atomicbitops.Bool
stack *stack.Stack
nicID tcpip.NICID
name string
isTap bool
mu endpointMutex `state:"nosave"`
onCloseAction func() `state:"nosave"`
persistent bool
closed bool
}
func (e *tunEndpoint) setPersistent(v bool) {
old := e.persistent.Swap(v)
if old == v {
e.mu.Lock()
if e.persistent == v || e.closed {
e.mu.Unlock()
return
}
e.persistent = v
e.mu.Unlock()
// Update refs without holding the lock.
if v {
e.IncRef()
} else {
@ -386,17 +394,19 @@ func (e *tunEndpoint) setPersistent(v bool) {
}
func (e *tunEndpoint) Close() {
if e.closed.Swap(true) {
e.mu.Lock()
if e.closed {
e.mu.Unlock()
return
}
if e.persistent.Load() {
e.DecRef(context.Background())
}
e.mu.Lock()
e.closed = true
decref := e.persistent
action := e.onCloseAction
e.onCloseAction = nil
e.mu.Unlock()
if decref {
e.DecRef(context.Background())
}
if action != nil {
action()
}

View file

@ -92,5 +92,5 @@ func deviceinitLockNames() {}
func init() {
deviceinitLockNames()
deviceprefixIndex = locking.NewMutexClass(reflect.TypeOf(deviceRWMutex{}), devicelockNames)
deviceprefixIndex = locking.NewMutexClass(reflect.TypeFor[deviceRWMutex](), devicelockNames)
}

View file

@ -60,5 +60,5 @@ func endpointinitLockNames() {}
func init() {
endpointinitLockNames()
endpointprefixIndex = locking.NewMutexClass(reflect.TypeOf(endpointMutex{}), endpointlockNames)
endpointprefixIndex = locking.NewMutexClass(reflect.TypeFor[endpointMutex](), endpointlockNames)
}