rofl0r / rofl0r/microsocks

SIGSEGV on FreeBSD

Open
#99 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
2.2k
Forks
353
Avg merge
1h 4m
Merged PRs (30d)
1

Description

microsocks crashes with SIGSEGV on FreeBSD because the default THREAD_STACK_SIZE (32KB) is insufficient when getaddrinfo triggers logging.
The crash occurs when getaddrinfo encounters a DNS anomaly (e.g., hostname mismatch) and attempts to log it via syslog. The call chain getaddrinfo -> nsdispatch -> syslog -> vfprintf consumes more stack space than available, leading to a stack overflow.

* thread #1, name = 'microsocks', stop reason = signal SIGSEGV
  * frame #0: 0x00000008229fbf87 libc.so.7`___lldb_unnamed_symbol4967 + 23
    frame #1: 0x00000008229fbd5b libc.so.7`vfprintf_l + 187
    frame #2: 0x00000008229f478f libc.so.7`fprintf + 191
    frame #3: 0x0000000822993588 libc.so.7`___lldb_unnamed_symbol4408 + 216
    frame #4: 0x00000008229933d6 libc.so.7`syslog + 214
    frame #5: 0x00000008229bbd5f libc.so.7`___lldb_unnamed_symbol4630 + 1023
    frame #6: 0x00000008229bb0d3 libc.so.7`___lldb_unnamed_symbol4627 + 1091
    frame #7: 0x00000008229cb72d libc.so.7`_nsdispatch + 1437
    frame #8: 0x00000008229b94a8 libc.so.7`___lldb_unnamed_symbol4616 + 120
    frame #9: 0x00000008229b9016 libc.so.7`getaddrinfo + 2870
    frame #10: 0x00000000002045a8 microsocks`resolve(host="alive.github.com", port=443, addr=0x0000000828c40a08) at server.c:14:9
    frame #11: 0x000000000020409e microsocks`connect_socks_target(buf="\U00000005\U00000001", n=23, client=0x00000326d661a218) at sockssrv.c:162:5

Increasing THREAD_STACK_SIZE to 64KB for FreeBSD fixes the issue.
After recompiling with the increased stack size, the process no longer segfaults. DNS anomalies are successfully logged to /var/log/messages.

Jan  8 19:27:00 vps0 microsocks[1338]: gethostby*.getanswer: asked for "lh3.googleusercontent.com", got "googlehosted.l.googleusercontent.com"
Jan  8 19:29:40 vps0 microsocks[1338]: gethostby*.getanswer: asked for "alive.github.com", got "live.github.com"

Environment:
OS: FreeBSD 14.2-RELEASE amd64
Microsocks versions: v1.0.5, v1.0.4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the FreeBSD-specific THREAD_STACK_SIZE definition and its use around resolve in server.c and connect_socks_target in sockssrv.c. Rebuild on FreeBSD and exercise a DNS lookup that triggers resolver logging. Done means the stack size is increased to 64KB for FreeBSD and the process no longer segfaults while DNS anomalies are logged.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
networking, operating-systems
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.