shadowsocks / shadowsocks-libev

Bug-fix-only libev port of shadowsocks. Future development moved to shadowsocks-rust
https://github.com/shadowsocks/shadowsocks-rust
GNU General Public License v3.0
15.79k stars 5.69k forks source link

ss-tunnel 3.0.0 Segmentation fault #1184

Closed sadoneli closed 7 years ago

sadoneli commented 7 years ago

Please answer these questions before submitting your issue. Thanks!

What version of shadowsocks-libev are you using?

3.0.0

What operating system are you using?

linux 2.6.36 asuswrt merlin

What did you do?

compile and run

What did you expect to see?

What did you see instead?

What is your config in detail (with all sensitive info masked)?

using this command line not work

admin@NETGEAR-BD26:/jffs# ss-tunnel -b 0.0.0.0 -s vps_ip_not_show -p 5071 -c /koolshare/ss/ss.json -l 7913 -L 8.8.8.8:53 -u
Segmentation fault

this is fine

ss-tunnel -b 0.0.0.0 -s vps_ip_not_show -p 5071 -m chacha20 -k mjy211 -l 7913 -L 8.8.8.8:53 -u
 2017-02-03 23:10:33 INFO: initializing ciphers... chacha20
 2017-02-03 23:10:33 INFO: UDP relay enabled

it seems the -c option can only use it alone in ss-tunnel,ss-local and ss-redir is ok

madeye commented 7 years ago

What's the config file in detail?

sadoneli commented 7 years ago
{
    "server":"vps_ip_not_show",
    "server_port":5071,
    "local_port":3333,
    "password":"mjy211",
    "timeout":600,
    "method":"chacha20"
}
xc2 commented 7 years ago

Could you please have a try with binaries I build: https://github.com/xc2/shadowsocks-libev-tomato/releases/tag/3.0.0-1

madeye commented 7 years ago

Could you try the latest commit? I cannot reproduce it locally.

madeye commented 7 years ago

@xc2 It looks very cool!

madeye commented 7 years ago

@xc2 You may add a link to your repo to our README with a pull request.

sadoneli commented 7 years ago

@xc2 your build works the same as mine, but still Segmentation fault in my scenario

sadoneli commented 7 years ago

@madeye the latest code still have this problem, maybe I should try toolchain with higher version of gcc

madeye commented 7 years ago

@sadoneli What's the last commit without this issue? Or could you build a debug version and run gdb our your router?

xc2 commented 7 years ago

@madeye Thank you. I will create a pr when I'm prepared.

sadoneli commented 7 years ago

In 2.6.1,it works fine,on the merlin router , I only need to generate one ss.json file on my router, and ss-locoal, ss-redir, ss-tunnel can use it by adding additional args, in the case if ss-redir ,I can use it directly by ss-redir -b 0.0.0.0 -c $CONFIG_FILE $ARG_OTA -u -f /var/run/shadowsocks.pid ss-local -b 0.0.0.0 -l 23456 -c $CONFIG_FILE $ARG_OTA -u and for ss-tunnel ss-tunnel -b 0.0.0.0 -s 127.0.0.1 -p 5071 -m chacha20 -k mjy211 -l 7913 -L 8.8.8.8:53 -u because I use KCP, so I can modifiy the server with additional arg -s 127.0.0.1

I didn't compile version between 2.6.1 and 3.0.0, so I don't known which version this issue begain to appear.

in 3.0.0 lateset code by this morning, ss-redir and ss-local works fine by command above ,but ss-tunnel still problem

sadoneli commented 7 years ago

ss-tunnel :https://github.com/koolshare/koolshare.github.io/blob/acelan_softcenter_ui/shadowsocks/shadowsocks/ss/start.sh#L189

ss-redir: https://github.com/koolshare/koolshare.github.io/blob/acelan_softcenter_ui/shadowsocks/shadowsocks/ss/start.sh#L545

ss-local:https://github.com/koolshare/koolshare.github.io/blob/acelan_softcenter_ui/shadowsocks/shadowsocks/ss/start.sh#L166

madeye commented 7 years ago

@sadoneli Without -u, would this issue happen?

sadoneli commented 7 years ago

admin@NETGEAR-BD26:/jffs# ss-tunnel -b 0.0.0.0 -s 47.90.. -p 5072 -c /koolshare/ss/ss.json -l 1055 -L 8.8.8.8:53 Segmentation fault admin@NETGEAR-BD26:/jffs# ss-tunnel -b 0.0.0.0 -s 47.90.. -p 5072 -c /koolshare/ss/ss.json -l 1055 -L 8.8.8.8:53 -u Segmentation fault admin@NETGEAR-BD26:/jffs# ss-tunnel -b 0.0.0.0 -s 47.90.. -p 5072 -c /koolshare/ss/ss.json -l 1055 -L 8.8.8.8:53 -U Segmentation fault

madeye commented 7 years ago

Could you try these commands?

ss-tunnel -b 0.0.0.0 -s 47.90.***.*** -p 5072 -c /koolshare/ss/ss.json -l 1055 -L 8.8.8.8:53 -m aes-128-gcm
ss-tunnel -b 0.0.0.0 -s 47.90.***.*** -p 5072 -c /koolshare/ss/ss.json -l 1055 -L 8.8.8.8:53 -m aes-128-ctr
ss-tunnel -s 47.90.***.*** -p 5072 -c /koolshare/ss/ss.json -l 1055 -L 8.8.8.8:53 -m aes-128-ctr

Also, could you try 6892951?

sadoneli commented 7 years ago
admin@NETGEAR-BD26:/jffs/.koolshare# ss-tunnel -b 0.0.0.0 -s 47.90.1.1 -p 5072 -c /koolshare/ss/ss.json -l 1057 -L 8.8.8.8:53 -m aes-128-gcm
Segmentation fault
admin@NETGEAR-BD26:/jffs/.koolshare# ss-tunnel -b 0.0.0.0 -s 47.90.1.1 -p 5072 -c /koolshare/ss/ss.json -l 1055 -L 8.8.8.8:53 -m aes-128-ctr
Segmentation fault
admin@NETGEAR-BD26:/jffs/.koolshare# ss-tunnel -s 47.90.1.1 -p 5072 -c /koolshare/ss/ss.json -l 1055 -L 8.8.8.8:53 -m aes-128-ctr
Segmentation fault

all https://github.com/shadowsocks/shadowsocks-libev/commit/68929513d31af4e90a3fb7eadc4938535b872519

madeye commented 7 years ago

What about this?

ss-tunnel -s 47.90.1.1 -p 5072 -c /koolshare/ss/ss.json -l 1055
sadoneli commented 7 years ago
admin@NETGEAR-BD26:/jffs# ss-tunnel -s 47.90.1.1 -p 5072 -c /koolshare/ss/ss.json -l 1055

shadowsocks-libev 3.0.0

  maintained by Max Lv <max.c.lv@gmail.com> and Linus Yang <laokongzi@gmail.com>

  usage:

    ss-tunnel

       -s <server_host>           Host name or IP address of your remote server.
       -p <server_port>           Port number of your remote server.
       -l <local_port>            Port number of your local server.
       -k <password>              Password of your remote server.
       -m <encrypt_method>        Encrypt method: rc4-md5, 
                                  aes-128-gcm, aes-192-gcm, aes-256-gcm,
                                  aes-128-cfb, aes-192-cfb, aes-256-cfb,
                                  aes-128-ctr, aes-192-ctr, aes-256-ctr,
                                  camellia-128-cfb, camellia-192-cfb,
                                  camellia-256-cfb, bf-cfb,
                                  chacha20-poly1305, chacha20-ietf-poly1305
                                  salsa20, chacha20 and chacha20-ietf.
                                  The default cipher is rc4-md5.

       [-a <user>]                Run as another user.
       [-f <pid_file>]            The file path to store pid.
       [-t <timeout>]             Socket timeout in seconds.
       [-c <config_file>]         The path to config file.
       [-n <number>]              Max number of open files.
       [-i <interface>]           Network interface to bind.
       [-b <local_address>]       Local address to bind.

       [-u]                       Enable UDP relay.
       [-U]                       Enable UDP relay and disable TCP relay.

       [-L <addr>:<port>]         Destination server address and port
                                  for local port forwarding.
       [--reuse-port]             Enable port reuse.
       [--mtu <MTU>]              MTU of your network interface.
       [--mptcp]                  Enable Multipath TCP on MPTCP Kernel.
       [--plugin <name>]          Enable SIP003 plugin. (Experimental)
       [--plugin-opts <options>]  Set SIP003 plugin options. (Experimental)

       [-v]                       Verbose mode.
       [-h, --help]               Print this message.
sadoneli commented 7 years ago

really odd

madeye commented 7 years ago

Then try this:

ss-tunnel -s 47.90.1.1 -p 5072 -c /koolshare/ss/ss.json -l 1055 -L 8.8.8.8

Also, could you add some printf() in the main() in tunnel.c? It will help to detect which part of code cause the issue.

sadoneli commented 7 years ago
admin@NETGEAR-BD26:/tmp/home/root# ss-tunnel -s 47.90.1.1 -p 5072 -c /koolshare/ss/ss.json -l 1055 -L 8.8.8.8
 2017-02-04 18:07:48 ERROR: tunnel port is not defined

I am not familiar with c, but I try my best to test it

add

when defined port 53

admin@NETGEAR-BD26:/tmp/home/root# ss-tunnel -s 47.90.1.1 -p 5072 -c /koolshare/ss/ss.json -l 1055 -L 8.8.8.8:53
Segmentation fault
madeye commented 7 years ago

It seems that the crash happens before LOGI("initializing ciphers... %s", method);, as no output of this line before segmentation fault.

But according to your new tests, it may happen after that line. So, we'd better add enough printf("Line number: %d", __LINE__); to locate the problem.

sadoneli commented 7 years ago

I have add some printf in the tunnel.c and found this place

printf("a=%d\n",7);
    // parse tunnel addr
    parse_addr(tunnel_addr_str, &tunnel_addr);

    if (tunnel_addr.port == NULL) {
        FATAL("tunnel port is not defined");
    }
printf("a=%d\n",8);

this is the log

admin@NETGEAR-BD26:/jffs# ./ss-tunnel -s 47.90.1.1 -p 5072 -c /koolshare/ss/ss.json -l 1055 -L 8.8.8.8:53
a=1
a=2
a=3
a=4
a=5
a=6
a=7
Segmentation fault

the program can no proceed to a=8

madeye commented 7 years ago

Cool! Let me look into that function.

sadoneli commented 7 years ago

to go futher more

printf("a=%d\n",7);
    // parse tunnel addr
    parse_addr(tunnel_addr_str, &tunnel_addr);
printf("a=%d\n",8);
    if (tunnel_addr.port == NULL) {
        FATAL("tunnel port is not defined");
    }
printf("a=%d\n",9);
admin@NETGEAR-BD26:/jffs# ./ss-tunnel -s 47.90.1.1 -p 5072 -c /koolshare/ss/ss.json -l 1055 -L 8.8.8.8:53
a=1
a=2
a=3
a=4
a=5
a=6
a=7
Segmentation fault

It seem iusse is on this line https://github.com/shadowsocks/shadowsocks-libev/blob/master/src/tunnel.c#L984

madeye commented 7 years ago

Please try dde1bf7.

sadoneli commented 7 years ago

nice! it works!

admin@NETGEAR-BD26:/jffs# ss-tunnel -b 0.0.0.0 -s 47.90.1.1 -p 5072 -c /koolshare/ss/ss.json  -l 1055 -L 8.8.8.8:53 -u
 2017-02-04 18:40:05 INFO: initializing ciphers... chacha20-ietf-poly1305
 2017-02-04 18:40:08 INFO: UDP relay enabled
 2017-02-04 18:40:08 INFO: listening at 0.0.0.0:1055
 2017-02-04 18:40:08 INFO: running from root user
madeye commented 7 years ago

Cool! Thanks for the debugging effort!

sadoneli commented 7 years ago

same word to you~