irungentoo / toxcore

The future of online communications.
https://tox.chat/
GNU General Public License v3.0
8.74k stars 1.27k forks source link

Segfault on Raspbian #1197

Closed gjedeer closed 9 years ago

gjedeer commented 9 years ago

I just built libtoxcore on Raspbian on a Raspberry pi. It failed tests and segfaults were reported:

root@raspberrypi:/home/pi/tuntox-build/toxcore# make check
make  check-recursive
make[1]: Entering directory '/home/pi/tuntox-build/toxcore'
Making check in build
make[2]: Entering directory '/home/pi/tuntox-build/toxcore/build'
make  encryptsave_test messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test dht_autotest 
make[3]: Entering directory '/home/pi/tuntox-build/toxcore/build'
  CC     ../auto_tests/encryptsave_test-encryptsave_test.o
  CCLD   encryptsave_test
  CC     ../auto_tests/messenger_autotest-messenger_test.o
  CCLD   messenger_autotest
  CC     ../auto_tests/crypto_test-crypto_test.o
  CCLD   crypto_test
  CC     ../auto_tests/network_test-network_test.o
  CCLD   network_test
  CC     ../auto_tests/assoc_test-assoc_test.o
../auto_tests/assoc_test.c: In function 'test_fillup':
../auto_tests/assoc_test.c:67:5: warning: this decimal constant is unsigned only in ISO C90 [enabled by default]
  CCLD   assoc_test
  CC     ../auto_tests/onion_test-onion_test.o
  CCLD   onion_test
  CC     ../auto_tests/TCP_test-TCP_test.o
  CCLD   TCP_test
  CC     ../auto_tests/tox_test-tox_test.o
  CCLD   tox_test
  CC     ../auto_tests/dht_autotest-dht_test.o
  CCLD   dht_autotest
make[3]: Leaving directory '/home/pi/tuntox-build/toxcore/build'
make  check-TESTS
make[3]: Entering directory '/home/pi/tuntox-build/toxcore/build'
Running suite(s): encryptsave
33%: Checks: 3, Failures: 1, Errors: 1
../auto_tests/encryptsave_test.c:60:F:save_friend:test_save_friend:0: Failed to create 2 tox instances
../auto_tests/encryptsave_test.c:120:E:keys:test_keys:0: (after this point) Test timeout expired
FAIL: encryptsave_test
/bin/bash: line 5: 31819 Segmentation fault      ${dir}$tst
FAIL: messenger_autotest
Running suite(s): Crypto
100%: Checks: 5, Failures: 0, Errors: 0
PASS: crypto_test
Running suite(s): Network
100%: Checks: 2, Failures: 0, Errors: 0
PASS: network_test
Running suite(s): Assoc
100%: Checks: 2, Failures: 0, Errors: 0
PASS: assoc_test
Running suite(s): Onion
0%: Checks: 1, Failures: 1, Errors: 0
../auto_tests/onion_test.c:136:F:basic:test_basic:0: Onion failed initializing.
FAIL: onion_test
Running suite(s): TCP
0%: Checks: 4, Failures: 3, Errors: 1
../auto_tests/TCP_test.c:36:F:basic:test_basic:0: Failed to create TCP relay server
../auto_tests/TCP_test.c:211:F:some:test_some:0: Failed to create TCP relay server
../auto_tests/TCP_test.c:373:F:client:test_client:0: Failed to create TCP relay server
../auto_tests/TCP_test.c:463:E:client_invalid:test_client_invalid:0: (after this point) Received signal 11 (Segmentation fault)
FAIL: TCP_test
Running suite(s): Tox
0%: Checks: 3, Failures: 3, Errors: 0
../auto_tests/tox_test.c:151:F:few_clients:test_few_clients:0: Failed to create 3 tox instances
../auto_tests/tox_test.c:374:F:many_clients:test_many_clients:0: Failed to create tox instances 0
../auto_tests/tox_test.c:490:F:many_group:test_many_group:0: Failed to create tox instances 0
FAIL: tox_test
Running suite(s): DHT
50%: Checks: 2, Failures: 1, Errors: 0
../auto_tests/dht_test.c:289:F:addto_lists_ipv6:test_addto_lists_ipv6:0: Failed to create Networking_Core
FAIL: dht_autotest
===============================
6 of 9 tests failed
Please report to https://tox.im
===============================
Makefile:2301: recipe for target 'check-TESTS' failed
make[3]: *** [check-TESTS] Error 1
make[3]: Leaving directory '/home/pi/tuntox-build/toxcore/build'
Makefile:2424: recipe for target 'check-am' failed
make[2]: *** [check-am] Error 2
make[2]: Leaving directory '/home/pi/tuntox-build/toxcore/build'
Makefile:436: recipe for target 'check-recursive' failed
make[1]: *** [check-recursive] Error 1
make[1]: Leaving directory '/home/pi/tuntox-build/toxcore'
Makefile:753: recipe for target 'check' failed
make: *** [check] Error 2

root@raspberrypi:/home/pi/tuntox-build/toxcore# uname -a
Linux raspberrypi 3.12.28+ #709 PREEMPT Mon Sep 8 15:28:00 BST 2014 armv6l GNU/Linux

root@raspberrypi:/home/pi/tuntox-build/toxcore# git rev-parse HEAD
13dd76995f05fd4759c8f639322671536014e14c

root@raspberrypi:/home/pi/tuntox-build/toxcore# cat /etc/debian_version 
7.6

I also compiled a program which links libtoxcore (the same system) and maybe its backtrace will be useful to you:

(gdb) run
Starting program: /home/pi/tuntox-build/tuntox/tuntox 

Program received signal SIGSEGV, Segmentation fault.
0x00058c90 in memcpy ()
(gdb) bt
#0  0x00058c90 in memcpy ()
#1  0x000d102c in __pointer_chk_guard_local ()
#2  0x000d102c in __pointer_chk_guard_local ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
dubslow commented 9 years ago

How much memory is there on this system?

Please also try commenting out line 162 of auto_tests/encryptsave_test.c, and make check again. (This line says DEFTESTCASE_SLOW(known_kdf, 60);.)

gjedeer commented 9 years ago
pi@raspberrypi ~ $ free -m
             total       used       free     shared    buffers     cached
Mem:           183         50        133          0          7         22
-/+ buffers/cache:         20        162
Swap:           99          0         99

I commented out that line, recompiled and it still doesn't pass the test:

make  check-recursive
make[1]: Entering directory '/home/pi/tuntox-build/toxcore'
Making check in build
make[2]: Entering directory '/home/pi/tuntox-build/toxcore/build'
make  encryptsave_test messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test dht_autotest 
make[3]: Entering directory '/home/pi/tuntox-build/toxcore/build'
make[3]: 'encryptsave_test' is up to date.
make[3]: 'messenger_autotest' is up to date.
make[3]: 'crypto_test' is up to date.
make[3]: 'network_test' is up to date.
make[3]: 'assoc_test' is up to date.
make[3]: 'onion_test' is up to date.
make[3]: 'TCP_test' is up to date.
make[3]: 'tox_test' is up to date.
make[3]: 'dht_autotest' is up to date.
make[3]: Leaving directory '/home/pi/tuntox-build/toxcore/build'
make  check-TESTS
make[3]: Entering directory '/home/pi/tuntox-build/toxcore/build'
Running suite(s): encryptsave
0%: Checks: 2, Failures: 1, Errors: 1
../auto_tests/encryptsave_test.c:60:F:save_friend:test_save_friend:0: Failed to create 2 tox instances
../auto_tests/encryptsave_test.c:120:E:keys:test_keys:0: (after this point) Test timeout expired
FAIL: encryptsave_test
/bin/bash: line 5:  2680 Segmentation fault      ${dir}$tst
FAIL: messenger_autotest
Running suite(s): Crypto
100%: Checks: 5, Failures: 0, Errors: 0
PASS: crypto_test
Running suite(s): Network
100%: Checks: 2, Failures: 0, Errors: 0
PASS: network_test
Running suite(s): Assoc
100%: Checks: 2, Failures: 0, Errors: 0
PASS: assoc_test
Running suite(s): Onion
0%: Checks: 1, Failures: 1, Errors: 0
../auto_tests/onion_test.c:136:F:basic:test_basic:0: Onion failed initializing.
FAIL: onion_test
Running suite(s): TCP
0%: Checks: 4, Failures: 3, Errors: 1
../auto_tests/TCP_test.c:36:F:basic:test_basic:0: Failed to create TCP relay server
../auto_tests/TCP_test.c:211:F:some:test_some:0: Failed to create TCP relay server
../auto_tests/TCP_test.c:373:F:client:test_client:0: Failed to create TCP relay server
../auto_tests/TCP_test.c:463:E:client_invalid:test_client_invalid:0: (after this point) Received signal 11 (Segmentation fault)
FAIL: TCP_test
Running suite(s): Tox
0%: Checks: 3, Failures: 3, Errors: 0
../auto_tests/tox_test.c:151:F:few_clients:test_few_clients:0: Failed to create 3 tox instances
../auto_tests/tox_test.c:374:F:many_clients:test_many_clients:0: Failed to create tox instances 0
../auto_tests/tox_test.c:490:F:many_group:test_many_group:0: Failed to create tox instances 0
FAIL: tox_test
Running suite(s): DHT
50%: Checks: 2, Failures: 1, Errors: 0
../auto_tests/dht_test.c:289:F:addto_lists_ipv6:test_addto_lists_ipv6:0: Failed to create Networking_Core
FAIL: dht_autotest
===============================
6 of 9 tests failed
Please report to https://tox.im
===============================
Makefile:2301: recipe for target 'check-TESTS' failed
make[3]: *** [check-TESTS] Error 1
make[3]: Leaving directory '/home/pi/tuntox-build/toxcore/build'
Makefile:2424: recipe for target 'check-am' failed
make[2]: *** [check-am] Error 2
make[2]: Leaving directory '/home/pi/tuntox-build/toxcore/build'
Makefile:436: recipe for target 'check-recursive' failed
make[1]: *** [check-recursive] Error 1
make[1]: Leaving directory '/home/pi/tuntox-build/toxcore'
Makefile:753: recipe for target 'check' failed
make: *** [check] Error 2
dubslow commented 9 years ago

I can't say for certain if toxcore can run on ~130 MiB of ram, but judging by all of the "cannot allocate" errors, apparently not.

gjedeer commented 9 years ago

I can't see any "cannot allocate" errors in the output. Unless you're certain that the SIGSEGV was because of null pointer.

gjedeer commented 9 years ago

Anyway, if there's a way to be certain, let me know so I can check. I don't understand your test framework so I can't figure it out myself.

dubslow commented 9 years ago

The output mentions which files and line numbers are failing the assertions.

For instance, this is the first error from your most recent paste:

../auto_tests/encryptsave_test.c:60:F:save_friend:test_save_friend:0: Failed to create 2 tox instances

The corresponding assertion: https://github.com/irungentoo/toxcore/blob/master/auto_tests/encryptsave_test.c#L60

Pretty much the only reason tox_new would fail is if there wasn't sufficient memory.

gjedeer commented 9 years ago

I've added 512 MB of swap and re-ran the test. It still fails with the same errors.

root@raspberrypi:/home/pi/tuntox-build/toxcore# free -m
             total       used       free     shared    buffers     cached
Mem:           183         71        112          0          5         41
-/+ buffers/cache:         23        159
Swap:          611          0        611

There is now more free memory than VIRT size of utox running on my desktop.

I made some more tests - wrote a small program: https://gist.github.com/gjedeer/4fafccd1802ebc62eb26 and ran it through gdb. I've set breakpoints on all returns from tox_new, then new_messenger and this led me to new_networking failing this check: https://github.com/irungentoo/toxcore/blob/master/toxcore/network.c#L480

Full gdb session: https://gist.github.com/gjedeer/90bef9cf444512321586

The constants are defined as following:

arm-linux-gnueabihf/bits/socket.h:78:#define    PF_INET         2       /* IP protocol family.  */
arm-linux-gnueabihf/bits/socket.h:86:#define    PF_INET6        10      /* IP version 6.  */
arm-linux-gnueabihf/bits/socket.h:121:#define   AF_INET         PF_INET
arm-linux-gnueabihf/bits/socket.h:129:#define   AF_INET6        PF_INET6
gjedeer commented 9 years ago

After a closer look it doesn't look like this line is actually executed. I compiled toxcore with DEBUG enabled just in new_networking and it prints:

Failed to get a socket?! 97, Address family not supported by protocol

which is printed here in code: https://github.com/irungentoo/toxcore/blob/master/toxcore/network.c#L505

gjedeer commented 9 years ago

...which led me to the discovery that raspbian doesn't have ipv6 enabled by default (need modprobe ipv6).

I'll leave this issue open - it's up to you to decide whether failing to initialize is the desired behavior if IPv6 is not supported/enabled.

GrayHatter commented 9 years ago

@irungentoo do you want to comment on this? or should we just close it as stale?