xjasonlyu / tun2socks

tun2socks - powered by gVisor TCP/IP stack
https://github.com/xjasonlyu/tun2socks/wiki
GNU General Public License v3.0
2.85k stars 404 forks source link

[Bug] tun2sock crash on macOS 13 Ventura #238

Closed Alkenso closed 1 year ago

Alkenso commented 1 year ago

Verify steps

Version

2.4.1

What OS are you seeing the problem on?

macOS

Description

Just start tun2sock, tried to open web page and got tool crash

CLI or Config

sudo ./tun2socks -device utun123 -proxy socks5://95.111.224.68:59166 -interface en0

Logs

INFO[0000] [DIALER] bind to interface: en0              
INFO[0000] [STACK] tun://utun123 <-> socks5://95.111.224.68:59166 
INFO[0039] [TCP] 198.18.0.1:61085 <-> 52.168.117.170:443 
INFO[0040] [TCP] 198.18.0.1:61087 <-> 17.57.172.11:443  
INFO[0041] [TCP] 192.168.64.5:55176 <-> 17.253.39.207:80 
INFO[0042] [TCP] 192.168.64.5:55177 <-> 142.250.203.195:80 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x103179e44]

goroutine 73 [running]:
github.com/xjasonlyu/tun2socks/v2/proxy.(*Socks5).DialUDP(0x14000113cb0, 0x14000206294)
    github.com/xjasonlyu/tun2socks/v2/proxy/socks5.go:124 +0x3f4
github.com/xjasonlyu/tun2socks/v2/proxy.DialUDP(...)
    github.com/xjasonlyu/tun2socks/v2/proxy/proxy.go:49
github.com/xjasonlyu/tun2socks/v2/tunnel.handleUDPConn({0x1033730d8?, 0x14000212280})
    github.com/xjasonlyu/tun2socks/v2/tunnel/udp.go:40 +0x180
created by github.com/xjasonlyu/tun2socks/v2/tunnel.process
    github.com/xjasonlyu/tun2socks/v2/tunnel/tunnel.go:33 +0x148

How to Reproduce

Just started tun2sock, tried to open web page and got tool crash

xjasonlyu commented 1 year ago

Hi, thanks for the feedback. I just confirmed the problem and yes it crashes. However, technically this is not a problem with tun2socks, but with your proxy server. When your local client sent a UDP request and forwarded by tun2socks, your proxy server replied an incorrect binding address socks5.Addr{0x3, 0x1, 0x0, 0xe7, 0x1e}, which is not followed by RFC standard and caused this issue.

In short, it's a SOCKS5 server UDP compatibility issue.

But thanks again for reporting a potential crash!