snell v6: panic (buffer overflow in ExtendHeader) when detouring snell v6 over snell v6
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 42/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- go
- Ambito
- networking
Direzione di ricerca
The crash is not in this repository: the failing frames are in snellv6/shaped.go in github.com/sagernet/sing-snell, at makeBufferRecord and the WriteVectorised call site that forwards split records to the detour writer. Start by reading makeBufferRecord, makeSliceRecord and the splitting in WriteVectorised to see where a start == 0 buffer reaches ExtendHeader, and confirm that path with the two snell v6 outbounds and the dd | curl upload from the report. Done means the chained-upload reproduction no longer panics and a regression test exercises two nested vectorised writers.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Operating system
macOS
System version
macOS 27.2.1 (Build 26B131)
Installation type
Original sing-box Command Line
If you are using a graphical client, please provide the version of the client.
No response
Version
sing-box version 1.14.4
Environment: go1.26.10 darwin/arm64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale,with_ccm,with_ocm,with_cloudflared,with_naive_outbound,with_usbip,with_openvpn,with_openconnect,badlinkname,tfogo_checklinkname0
Revision: c005f35300ce76427dc285481ec5695f5b179cd2
CGO: enabled
Description
Chaining a snell v6 outbound via detour over another snell v6 outbound causes a deterministic panic: buffer overflow: capacity ..., start 0, need ... when uploading enough data to split records in snellv6.(*vectorisedShapedWriter).WriteVectorised.
Root cause in github.com/sagernet/sing-snell (v0.0.0-20260904135315-bc5a12ac736f in v1.14.4, and the same code remains in v0.0.0-20261110094602-04667b0a321c currently referenced by testing):
- When the outer
snellv6.(*vectorisedShapedWriter).WriteVectorisedreceives a buffer larger thanpayloadLimit, it splits the payload viamakeSliceRecord(snellv6/shaped.go:48), allocating new buffers withbuf.NewSize(...)(start == 0, zero headroom). - It passes those
start == 0buffers tow.upstream.WriteVectorised(flushRecords)(snellv6/shaped.go:292), which is the innersnellv6.(*vectorisedShapedWriter)from thedetouroutbound. - For each buffer with
dataLen <= payloadLimit, the innerWriteVectorisedcallsshapedWriter.makeBufferRecord(buffer)(snellv6/shaped.go:275→shaped.go:89), which unconditionally callsbuffer.ExtendHeader(frontLen)without checkingbuffer.Start() >= frontLen(or falling back tomakeSliceRecord), causingbuf.(*Buffer).ExtendHeaderto panic.
Notes:
- Reproduces both with
reuse: true(viareuseVectorisedWriter.WriteVectorised, originally hit on iOS NetworkExtension 1.14.4) and with defaultreuse: false(viaclientVectorisedWriter.WriteVectorised, shown below). - Related upstream issue: SagerNet/sing-snell#4.
Reproduction
- Save the following minimal
server.jsonandclient.json:
server.json:
{
"log": {
"level": "debug"
},
"inbounds": [
{
"type": "snell",
"tag": "snell-in-1",
"listen": "127.0.0.1",
"listen_port": 18081,
"version": 6,
"psk": "test-snell-psk-123456"
},
{
"type": "snell",
"tag": "snell-in-2",
"listen": "127.0.0.1",
"listen_port": 18082,
"version": 6,
"psk": "test-snell-psk-123456"
}
],
"outbounds": [
{
"type": "direct"
}
]
}
client.json:
{
"log": {
"level": "debug"
},
"inbounds": [
{
"type": "socks",
"listen": "127.0.0.1",
"listen_port": 18080
}
],
"outbounds": [
{
"type": "snell",
"tag": "snell-hop1",
"server": "127.0.0.1",
"server_port": 18081,
"version": 6,
"psk": "test-snell-psk-123456"
},
{
"type": "snell",
"tag": "snell-hop2",
"server": "127.0.0.1",
"server_port": 18082,
"version": 6,
"psk": "test-snell-psk-123456",
"detour": "snell-hop1"
}
],
"route": {
"final": "snell-hop2"
}
}
- Start a local HTTP POST sink on
127.0.0.1:18083,sing-box run -c server.json, andsing-box run -c client.json:
python3 -c '
import http.server, socketserver
class H(http.server.BaseHTTPRequestHandler):
def do_POST(self):
n = int(self.headers.get("Content-Length", 0))
while n > 0:
chunk = self.rfile.read(min(n, 65536))
if not chunk: break
n -= len(chunk)
self.send_response(200); self.end_headers(); self.wfile.write(b"ok\n")
def log_message(self, *a): pass
socketserver.TCPServer.allow_reuse_address = True
with socketserver.TCPServer(("127.0.0.1", 18083), H) as s: s.handle_request()
' &
sing-box run -c server.json &
sing-box run -c client.json &
- Upload 4 MiB through the local SOCKS5 inbound:
dd if=/dev/zero bs=1048576 count=4 2>/dev/null | curl -sS -x socks5h://127.0.0.1:18080 --data-binary @- http://127.0.0.1:18083/
The client sing-box process immediately crashes with panic: buffer overflow: capacity 1329,start 0, need 118.
Logs
# Client log (complete):
INFO[0000] inbound/socks[0]: tcp server started at 127.0.0.1:18080
INFO[0000] network: updated default interface en0, index 14
INFO[0000] network: updated network environment: gateway [10.13.128.1 fe80::62db:15ff:fe7c:2], gateway_mac [60:db:15:7c:00:02 60:db:15:7c:00:02]
INFO[0000] sing-box started (0.00s)
INFO[0000] [3563243450 0ms] inbound/socks[0]: inbound connection from 127.0.0.1:61463
INFO[0000] [3563243450 0ms] inbound/socks[0]: inbound connection to 127.0.0.1:18083
INFO[0000] [3563243450 0ms] outbound/snell[snell-hop2]: outbound connection to 127.0.0.1:18083
INFO[0000] [3563243450 0ms] outbound/snell[snell-hop1]: outbound connection to 127.0.0.1:18082
panic: buffer overflow: capacity 1329,start 0, need 118
goroutine 76 [running]:
github.com/sagernet/sing/common/buf.(*Buffer).ExtendHeader(0x2bd33b56c040, 0x76)
github.com/sagernet/[email protected]/common/buf/buffer.go:116 +0x13c
github.com/sagernet/sing-snell/snellv6.(*shapedWriter).makeBufferRecord(0x2bd33b3eae80, 0x2bd33b56c040)
github.com/sagernet/[email protected]/snellv6/shaped.go:89 +0xcc
github.com/sagernet/sing-snell/snellv6.(*vectorisedShapedWriter).WriteVectorised(0x2bd33b662048, {0x2bd33b496280, 0xb, 0x33eb?})
github.com/sagernet/[email protected]/snellv6/shaped.go:275 +0x32c
github.com/sagernet/sing-snell/snellv6.(*clientVectorisedWriter).WriteVectorised(0x2bd33b3eae00?, {0x2bd33b496280, 0xb, 0x10})
github.com/sagernet/[email protected]/snellv6/client.go:231 +0x188
github.com/sagernet/sing-snell/snellv6.(*vectorisedShapedWriter).WriteVectorised(0x2bd33b662030, {0x2bd33b52dec0, 0x8, 0x106cbf980?})
github.com/sagernet/[email protected]/snellv6/shaped.go:292 +0x1d0
github.com/sagernet/sing-snell/snellv6.(*clientVectorisedWriter).WriteVectorised(0x2bd33b4e6090?, {0x2bd33b52dec0, 0x8, 0x8})
github.com/sagernet/[email protected]/snellv6/client.go:231 +0x188
github.com/sagernet/sing/common/bufio.copyWaitVectorisedWithPool(0x2bd33b333ca0, {0x106d42020, 0x2bd33b662018}, {0x106d4b390, 0x2bd33b4e6090}, 0x2bd33b702001?)
github.com/sagernet/[email protected]/common/bufio/copy_direct.go:87 +0xa0
github.com/sagernet/sing/common/bufio.copyWaitWithPool(0x2bd33b333ca0, {0x114a23200, 0x2bd33b564600}, {0x106d48a40, 0x2bd33b4ce000}, {0x106d4b3b8, 0x2bd33b4600c0}, {0xc7e, 0x20, 0x2edd, ...})
github.com/sagernet/[email protected]/common/bufio/copy_direct.go:65 +0x290
github.com/sagernet/sing/common/bufio.copyExtended(0x2bd33b333ca0, {0x114a23200, 0x2bd33b564600}, {0x106d48a40, 0x2bd33b4ce000})
github.com/sagernet/[email protected]/common/bufio/copy.go:128 +0xd4
github.com/sagernet/sing/common/bufio.CopyWithCounters({0x11477edd0, 0x2bd33b564600}, {0x106d39f60?, 0x2bd33b702038?}, {0x11477ee10, 0x2bd33b218318}, {0x0, 0x0, 0x0}, {0x0, ...}, ...)
github.com/sagernet/[email protected]/common/bufio/copy.go:99 +0x530
github.com/sagernet/sing/common/bufio.CopyWithIncreateBuffer({0x11477edd0?, 0x2bd33b564600?}, {0x11477ee10, 0x2bd33b218318}, 0x7d000, 0x8)
github.com/sagernet/[email protected]/common/bufio/copy.go:58 +0x36c
github.com/sagernet/sing-box/route.(*ConnectionManager).connectionCopy(0x2bd33b6377c0, {0x106d647f8, 0x2bd33b6f4270}, {0x106d82a38, 0x2bd33b218318}, {0x106d83068, 0x2bd33b564600}, 0x0, 0x2bd33b21a6b0, 0x0)
github.com/sagernet/sing-box/route/conn.go:294 +0xa8
created by github.com/sagernet/sing-box/route.(*ConnectionManager).NewConnection in goroutine 51
github.com/sagernet/sing-box/route/conn.go:160 +0x528
# Server log (complete):
INFO[0000] inbound/snell[snell-in-1]: tcp server started at 127.0.0.1:18081
INFO[0000] inbound/snell[snell-in-2]: tcp server started at 127.0.0.1:18082
INFO[0000] network: updated default interface en0, index 14
INFO[0000] network: updated network environment: gateway [10.13.128.1 fe80::62db:15ff:fe7c:2], gateway_mac [60:db:15:7c:00:02 60:db:15:7c:00:02]
INFO[0000] sing-box started (0.00s)
INFO[0000] [3157553626 0ms] inbound/snell[snell-in-1]: inbound connection from 127.0.0.1:61464
INFO[0000] [3157553626 0ms] inbound/snell[snell-in-1]: inbound connection to 127.0.0.1:18082
INFO[0000] [3157553626 0ms] outbound/direct[0]: outbound connection to 127.0.0.1:18082
INFO[0000] [3176775297 0ms] inbound/snell[snell-in-2]: inbound connection from 127.0.0.1:61465
INFO[0000] [3176775297 0ms] inbound/snell[snell-in-2]: inbound connection to 127.0.0.1:18083
INFO[0000] [3176775297 0ms] outbound/direct[0]: outbound connection to 127.0.0.1:18083
DEBUG[0002] [3157553626 1.2s] connection: connection upload finished
DEBUG[0002] [3176775297 1.2s] connection: connection upload finished
DEBUG[0002] [3176775297 1.2s] connection: connection download finished
DEBUG[0003] [3157553626 2.3s] inbound/snell[snell-in-1]: connection closed: snell: serve 127.0.0.1:61464: context canceled
Supporter
- I am a sponsor
Integrity requirements
- I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
- I confirm that I have provided the server and client configuration files and process that can be reproduced locally, instead of a complicated client configuration file that has been stripped of sensitive data.
- I confirm that I have provided the simplest configuration that can be used to reproduce the error I reported, instead of depending on remote servers, TUN, graphical interface clients, or other closed-source software.
- I confirm that I have provided the complete configuration files and logs, rather than just providing parts I think are useful out of confidence in my own intelligence.
- Lingua principale
- Go
- Stelle
- 40.4k
- Fork
- 5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di SagerNet/sing-box
-
`check` and startup are quadratic in outbound group size since 1.14.4 (duplicate tag check)Forse già presa @Tidehyc l’ha presa 5 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
database file removal errorsAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 89/100
Tutte le issue di SagerNet/sing-box
Issue simili
-
good first issue tools
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
Edwin-metcalf/MetCode#76 ·
I maintainer di solito rispondono entro 1 giorno
-
-diff's removed-name budget ignores the names the -ptr pass testedForse già presa @nova-loop l’ha presa oggi. Apertaarea: cli bug good first issue severity: low
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
TMHSDigital/subenum#495 ·
I maintainer di solito rispondono entro 1 giorno
-
bug effort:s impact:med raised-by:worker risk:low to:worker
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
medici-finance/assay#8120 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
factory:subtask
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
reportedBy/community
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
openchoreo/openchoreo#5751 ·
I maintainer di solito rispondono entro 1 giorno