jimmie316 / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Linking libtorsocks with libtcmalloc results in SIGSEGV #679

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Any application that is linked against libtcmalloc gets SISEGV if it's being 
run with libtorsocks preloaded. However, it depends on preloading order.

If libtorsocks is preloaded first, app segfaults:

===
[~]$ LD_PRELOAD="/usr/lib64/torsocks/libtorsocks.so 
/usr/lib64/libtcmalloc_debug.so" uname -a
[1]    7817 segmentation fault (core dumped)  LD_PRELOAD= uname -a
===

If, instead, libtcmalloc is preloaded first, everything is OK:

===
[~]$ LD_PRELOAD="/usr/lib64/libtcmalloc_debug.so 
/usr/lib64/torsocks/libtorsocks.so" uname -a
Linux spock 3.19.0-pf3 #1 SMP PREEMPT Tue Mar 24 17:14:04 EET 2015 x86_64 
GNU/Linux
===

The problem is that if an app in question is linked against libtcmalloc, 
torifying it via "torify" or "torsocks" wrapper always leads to segfault 
because libtorsocks is loaded before libtcmalloc.

Attempt made to debug any app leads to non-informative backtrace:

===
#0  0x0000000000000000 in ?? ()
#1  0x00007ffff725e40c in ?? () from /usr/lib/libtcmalloc_debug.so.4
#2  0x00007ffff725ed3f in ?? () from /usr/lib/libtcmalloc_debug.so.4
#3  0x00007ffff725ef49 in NumCPUs() () from /usr/lib/libtcmalloc_debug.so.4
#4  0x00007ffff723b439 in ?? () from /usr/lib/libtcmalloc_debug.so.4
#5  0x00007ffff7dea1fa in call_init.part () from /lib64/ld-linux-x86-64.so.2
#6  0x00007ffff7dea30b in _dl_init () from /lib64/ld-linux-x86-64.so.2
#7  0x00007ffff7ddbdba in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
#8  0x0000000000000003 in ?? ()
#9  0x00007fffffffe47a in ?? ()
#10 0x00007fffffffe4aa in ?? ()
#11 0x00007fffffffe4af in ?? ()
#12 0x0000000000000000 in ?? ()
===

I use torsocks v2.0.0 and libtcmalloc v2.4.

So my questions are:

1. should this be libtorsocks or libtcmalloc issue?
2. how should I get more info on this bug?
3. what should be done to fix the issue?

Original issue reported on code.google.com by pfac...@gmail.com on 4 Apr 2015 at 2:34

GoogleCodeExporter commented 9 years ago
Here is a link to TOR Project Trac ticket opened by me:

https://trac.torproject.org/projects/tor/ticket/15584

Original comment by pfac...@gmail.com on 4 Apr 2015 at 2:36

GoogleCodeExporter commented 9 years ago
Looks like something within torsocks. I was able to minimize problem as follows:

/*
 * Example .so library which somehow crashes torsocks.so.
 *
 * # gcc -shared -O1 -Wall -ggdb3 tsocks-crasher.c -fPIC -o tsocks-crasher.so
 * # LD_PRELOAD='/usr/lib/torsocks/libtorsocks.so /root/src/test/tsocks-crasher.so' /bin/true
 *
 */

__attribute__((constructor))
static void init(void)
{
    extern int close(int);
    close(0);
}

Original comment by alkondratenko on 4 Apr 2015 at 9:18

GoogleCodeExporter commented 9 years ago
BTW libtcmalloc_debug.so is not intended for "production" use. It's essentially 
malloc debugger. Consider using libtcmalloc_minimal.so or libtcmalloc.so 
instead.

It does not make a difference in this case though.

Original comment by alkondratenko on 4 Apr 2015 at 9:20

GoogleCodeExporter commented 9 years ago
Seems to be fixed by torsocks team.

https://trac.torproject.org/projects/tor/ticket/15584#comment:4

Original comment by pfac...@gmail.com on 12 May 2015 at 4:19

GoogleCodeExporter commented 9 years ago
Great. Closing then.

Original comment by alkondratenko on 17 May 2015 at 6:53