rofl0r / microsocks

tiny, portable SOCKS5 server with very moderate resource usage
Other
1.58k stars 275 forks source link

buffer overflow detected #66

Open eliotalanfoss opened 1 year ago

eliotalanfoss commented 1 year ago

When running the socks server as a systemd unit, and increasing the soft limit of the number of open files in the systemd unit file to 500000, I periodically get the service crashing because the microsocks program terminates with a *** buffer overflow detected ***: terminated I increased the file limit in order to accomadate more connections simultaneously, but now I am running into this problem. Is it a bug?

rofl0r commented 1 year ago

maybe. could you enable core dumps, rebuild microsocks with debug info make CFLAGS="-O0 -g3", and then load the core with gdb next time it happens ? that would give us a backtrace pointing to where it happens. does this happen only with the high fd limit ?

clyfish commented 10 months ago

Version: be545814aeca1158ae38e2d6c66b1197679dab63

┌──Register group: general─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│rax            0x0      0                                            rbx            0x0      0                                            │
│rcx            0x7fcf8f7c54fd   140529442247933                      rdx            0x0      0                                            │
│rsi            0x0      0                                            rdi            0x0      0                                            │
│rbp            0x7fcf8c1c9f90   0x7fcf8c1c9f90                       rsp            0x7fcf8c1c9ae0   0x7fcf8c1c9ae0                       │
│r8             0x7fcf8c1ca700   140529385645824                      r9             0x18     24                                           │
│r10            0x10     16                                           r11            0x0      0                                            │
│r12            0x0      0                                            r13            0x7fcf8c1ca9c0   140529385646528                      │
│r14            0x7fcf8c1ca700   140529385645824                      r15            0x0      0                                            │
│rip            0x401e89 0x401e89 <clientthread+474>                  eflags         0x10217  [ CF PF AF IF RF ]                           │
│cs             0x33     51                                           ss             0x2b     43                                           │
   ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
   │0x401e75 <clientthread+454>     cmpl   $0xffffffff,-0x4(%rbp)                                                                          │
   │0x401e79 <clientthread+458>     je     0x401e85 <clientthread+470>                                                                     │
   │0x401e7b <clientthread+460>     mov    -0x4(%rbp),%eax                                                                                 │
   │0x401e7e <clientthread+463>     mov    %eax,%edi                                                                                       │
   │0x401e80 <clientthread+465>     callq  0x400eb0 <close@plt>                                                                            │
   │0x401e85 <clientthread+470>     mov    -0x10(%rbp),%rax                                                                                │
  >│0x401e89 <clientthread+474>     mov    0x24(%rax),%eax                                                                                 │
   │0x401e8c <clientthread+477>     mov    %eax,%edi                                                                                       │
   │0x401e8e <clientthread+479>     callq  0x400eb0 <close@plt>                                                                            │
   │0x401e93 <clientthread+484>     mov    -0x10(%rbp),%rax                                                                                │
   │0x401e97 <clientthread+488>     movl   $0x1,0x2c(%rax)                                                                                 │
   └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
multi-thre Thread 0x7fcf8 In: clientthread                                                                          Line: ??   PC: 0x401e89
rofl0r commented 10 months ago

why are you testing a version from 2019 ? use latest git. also i don't see a usable backtrace in your paste. compile with -g3 to get source-level debug info instead of x86 asm.

clyfish commented 10 months ago

@rofl0r Because it was launched three years ago. Crashed on this line: https://github.com/rofl0r/microsocks/blob/be545814aeca1158ae38e2d6c66b1197679dab63/sockssrv.c#L335

rofl0r commented 10 months ago

well, i studied the code again and can't see anything that could cause this. i'd suggest you get the latest code, rebuild it with address sanitizer, and wait for the next crash, which will hopefully be accompanied with useful output from asan.

clyfish commented 10 months ago

OK.