SagerNet / sing-box

The universal proxy platform
https://sing-box.sagernet.org/
Other
18.24k stars 2.18k forks source link

panic: buffer overflow #117

Closed Gzxhwq closed 1 year ago

Gzxhwq commented 1 year ago

Welcome

Description of the problem

Get crash when connecting with shadowsocks 2022 inbound from latest dev-net branch commit.

Version of sing-box

```console $ sing-box version sing-box version v1.1-beta8-5-g46d6d4f Environment: go1.19.1 linux/amd64 Tags: with_quic,with_grpc,with_wireguard,with_shadowsocksr,with_utls,with_acme,with_gvisor,with_clash_api Revision: 46d6d4f27710d73a1956a0601ec88d051e918c01 CGO: disabled ```

Server and client configuration file

```console { "log": { "disabled": false, "level": "debug", "output": "/etc/sing-box/sing-box.log", "timestamp": true }, "experimental": { "clash_api": { "external_controller": "0.0.0.0:9090", "external_ui": "", "secret": "", "default_mode": "rule", "store_selected": true, "cache_file": "cache.db" } }, "dns": { "servers": [ { "tag": "google", "address": "tls://8.8.8.8" }, { "tag": "local", "address": "tls://1.12.12.12", "detour": "direct" } ], "rules": [ { "domain": "mydomain.com", "geosite": "cn", "server": "local" } ], "strategy": "ipv4_only" }, "inbounds": [ { "type": "tun", "inet4_address": "172.19.0.1/30", "auto_route": true, "endpoint_independent_nat": true, "stack": "system", "sniff": true }, { "type": "shadowsocks", "tag": "Mobile", "listen": "::", "listen_port": 18650, "method": "2022-blake3-aes-128-gcm", "password": " ", "sniff": true } ], "outbounds": [ { "type": "selector", "tag": "Home", "outbounds": [ "main", "backup", "direct", "aaa", "bbb", "ccc", "ddd", "eee" ], "default": "main" }, { "type": "urltest", "tag": "main", "outbounds": [ "aaa", "bbb", "ccc" ], "url": "http://www.gstatic.com/generate_204", "interval": "1m", "tolerance": 50 }, { "type": "urltest", "tag": "backup", "outbounds": [ "ddd", "eee" ], "url": "http://www.gstatic.com/generate_204", "interval": "1m", "tolerance": 50 }, { "type": "shadowsocks", "tag": "ddd", "detour": "shadowtls", "method": "2022-blake3-aes-128-gcm", "password": " ", "multiplex": { "enabled": true, "protocol": "smux", "max_connections": 4, "min_streams": 4 } }, { "type": "shadowtls", "tag": "shadowtls", "server": " ", "server_port": 11111, "tls": { "enabled": true, "server_name": "www.yahoo.com" } }, .................................................................................. ................................................................................ ```

Server and client log file

```console panic: buffer overflow: cap 16384,start 0, need 42 goroutine 801 [running]: github.com/sagernet/sing/common/buf.(*Buffer).ExtendHeader(0xc00030be80, 0x2a) github.com/sagernet/sing@v0.0.0-20220926054900-7209937cc235/common/buf/buffer.go:150 +0x1b9 github.com/sagernet/sing-shadowsocks/shadowaead_2022.(*serverPacketWriter).WritePacket(0xc000389c40, 0xc00030be80, {{{0x0, 0xffff8efb2aaa}, 0xc000010030}, 0x1bb, {0x0, 0x0}}) github.com/sagernet/sing-shadowsocks@v0.0.0-20220819002358-7461bb09a8f6/shadowaead_2022/service.go:531 +0x1e5 github.com/sagernet/sing/common/udpnat.(*conn).WritePacket(0xc00021e060?, 0x1c4c410?, {{{0x0, 0xffff8efb2aaa}, 0xc000010030}, 0x1bb, {0x0, 0x0}}) github.com/sagernet/sing@v0.0.0-20220926054900-7209937cc235/common/udpnat/service.go:158 +0x5d github.com/sagernet/sing-box/experimental/trackerconn.(*PacketConn).WritePacket(0xc00024dd60, 0xc00030be80?, {{{0x0, 0xffff8efb2aaa}, 0xc000010030}, 0x1bb, {0x0, 0x0}}) github.com/sagernet/sing-box/experimental/trackerconn/packet_conn.go:31 +0x76 github.com/sagernet/sing/common/bufio.CopyPacket({0x7fffd04e8658, 0xc00024dd80}, {0x7fffd04e8678?, 0xc00007dbd0?}) github.com/sagernet/sing@v0.0.0-20220926054900-7209937cc235/common/bufio/copy.go:250 +0x5ae github.com/sagernet/sing/common/bufio.CopyPacketConn.func2({0x0?, 0x0?}) github.com/sagernet/sing@v0.0.0-20220926054900-7209937cc235/common/bufio/copy.go:324 +0x6c github.com/sagernet/sing/common/task.(*Group).Run.func1() github.com/sagernet/sing@v0.0.0-20220926054900-7209937cc235/common/task/task.go:59 +0x93 created by github.com/sagernet/sing/common/task.(*Group).Run github.com/sagernet/sing@v0.0.0-20220926054900-7209937cc235/common/task/task.go:58 +0x54a ```
nekohasekai commented 1 year ago

Try latest commit

Gzxhwq commented 1 year ago

Fixed https://github.com/SagerNet/sing-box/commit/1e510511aec65023c8ad9dbe95d59a452760fc3b