Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psi_phasing crashes when bit length is less than 25 #23

Open
schoppmp opened this issue Apr 28, 2017 · 0 comments
Open

psi_phasing crashes when bit length is less than 25 #23

schoppmp opened this issue Apr 28, 2017 · 0 comments

Comments

@schoppmp
Copy link
Contributor

The example psi_phasing.exe crashes when used with bit-lengths that can be represented in less than 4 bytes. For example, calling

bin/psi_phasing.exe -r 0 -n 100 -b 24 & bin/psi_phasing.exe -r 1 -n 100 -b 24

gives the following error:

[1] 6185
psi_phasing.exe: common/phasing_circuit.cpp:187: int32_t test_phasing_circuit(e_role, char*, uint16_t, seclvl, uint32_t, uint32_t, uint32_t, double, uint32_t, e_mt_gen_alg, e_sharing, int, uint32_t, uint32_t): Assertion `circ_inter_ctr == ver_inter_ctr' failed.
32.115	0.98	968.399	2536922
[1]  + 6185 done       bin/psi_phasing.exe -r 0 -n 100 -b 24
[2]    6186 abort (core dumped)  bin/psi_phasing.exe -r 1 -n 100 -b 24

If the argument to the -b flag is set to 25 or higher, it works without any problems.

Compiling with CFLAGS=-g and calling the crashing process with valgrind indicates memory errors in the hashElement and test_phasing_circuit functions:

bin/psi_phasing.exe -r 0 -n 100 -b 24 & valgrind bin/psi_phasing.exe -r 1 -n 100 -b 24 
[1] 19652
==19653== Memcheck, a memory error detector
==19653== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==19653== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==19653== Command: bin/psi_phasing.exe -r 1 -n 100 -b 24
==19653== 
==19653== Warning: set address range perms: large range [0x903a040, 0x1a2e2840) (defined)
==19653== Thread 10:
==19653== Invalid write of size 4
==19653==    at 0x4192E0: hashElement (hashing_util.h:182)
==19653==    by 0x4192E0: insert_element (simple_hashing.cpp:129)
==19653==    by 0x4192E0: gen_entries(void*) (simple_hashing.cpp:119)
==19653==    by 0x52D82E6: start_thread (in /usr/lib/libpthread-2.25.so)
==19653==    by 0x677A54E: clone (in /usr/lib/libc-2.25.so)
==19653==  Address 0x1cebfbc0 is 0 bytes inside a block of size 3 alloc'd
==19653==    at 0x4C2CF35: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==19653==    by 0x4191F7: gen_entries(void*) (simple_hashing.cpp:114)
==19653==    by 0x52D82E6: start_thread (in /usr/lib/libpthread-2.25.so)
==19653==    by 0x677A54E: clone (in /usr/lib/libc-2.25.so)
==19653== 
==19653== Invalid write of size 4
==19653==    at 0x419F6D: hashElement (hashing_util.h:182)
==19653==    by 0x419F6D: gen_cuckoo_entry (cuckoo.cpp:189)
==19653==    by 0x419F6D: gen_cuckoo_entries(void*) (cuckoo.cpp:174)
==19653==    by 0x52D82E6: start_thread (in /usr/lib/libpthread-2.25.so)
==19653==    by 0x677A54E: clone (in /usr/lib/libc-2.25.so)
==19653==  Address 0x1d2b0080 is 0 bytes inside a block of size 3 alloc'd
==19653==    at 0x4C2CF35: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==19653==    by 0x419ED2: gen_cuckoo_entry (cuckoo.cpp:187)
==19653==    by 0x419ED2: gen_cuckoo_entries(void*) (cuckoo.cpp:174)
==19653==    by 0x52D82E6: start_thread (in /usr/lib/libpthread-2.25.so)
==19653==    by 0x677A54E: clone (in /usr/lib/libc-2.25.so)
==19653== 
==19653== Thread 1:
==19653== Invalid read of size 4
==19653==    at 0x4183DC: test_phasing_circuit(e_role, char*, unsigned short, SECURITYLEVELS, unsigned int, unsigned int, unsigned int, double, unsigned int, e_mt_gen_alg, e_sharing, int, unsigned int, unsigned int) (phasing_circuit.cpp:126)
==19653==    by 0x405AD1: main (psi_phasing.cpp:110)
==19653==  Address 0x1d2e0434 is 0 bytes after a block of size 36 alloc'd
==19653==    at 0x4C2AF1F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==19653==    by 0x41A564: cuckoo_hashing(unsigned char*, unsigned int, unsigned int, unsigned int, unsigned int*, unsigned int*, unsigned int*, unsigned int, unsigned char**, unsigned int, unsigned int**, unsigned int, prf_state_ctx*) (cuckoo.cpp:128)
==19653==    by 0x417604: ClientHashingRoutine(unsigned char*, unsigned int, unsigned int, unsigned int, unsigned char**, unsigned int*, unsigned int*, unsigned char**, unsigned int, unsigned int**, unsigned int, crypto*, unsigned int) (phasing_circuit.cpp:364)
==19653==    by 0x418110: test_phasing_circuit(e_role, char*, unsigned short, SECURITYLEVELS, unsigned int, unsigned int, unsigned int, double, unsigned int, e_mt_gen_alg, e_sharing, int, unsigned int, unsigned int) (phasing_circuit.cpp:83)
==19653==    by 0x405AD1: main (psi_phasing.cpp:110)
==19653== 
psi_phasing.exe: common/phasing_circuit.cpp:187: int32_t test_phasing_circuit(e_role, char*, uint16_t, seclvl, uint32_t, uint32_t, uint32_t, double, uint32_t, e_mt_gen_alg, e_sharing, int, uint32_t, uint32_t): Assertion `circ_inter_ctr == ver_inter_ctr' failed.
==19653== 
==19653== Process terminating with default action of signal 6 (SIGABRT): dumping core
==19653==    at 0x66C1A10: raise (in /usr/lib/libc-2.25.so)
==19653==    by 0x66C3139: abort (in /usr/lib/libc-2.25.so)
==19653==    by 0x66BA606: __assert_fail_base (in /usr/lib/libc-2.25.so)
==19653==    by 0x66BA6B1: __assert_fail (in /usr/lib/libc-2.25.so)
==19653==    by 0x418CEC: test_phasing_circuit(e_role, char*, unsigned short, SECURITYLEVELS, unsigned int, unsigned int, unsigned int, double, unsigned int, e_mt_gen_alg, e_sharing, int, unsigned int, unsigned int) (phasing_circuit.cpp:187)
==19653==    by 0x405AD1: main (psi_phasing.cpp:110)
==19653== 
==19653== HEAP SUMMARY:
==19653==     in use at exit: 289,114,248 bytes in 5,558 blocks
==19653==   total heap usage: 44,972 allocs, 39,414 frees, 314,858,330 bytes allocated
==19653== 
==19653== LEAK SUMMARY:
==19653==    definitely lost: 35,264 bytes in 323 blocks
==19653==    indirectly lost: 3,576 bytes in 322 blocks
==19653==      possibly lost: 2,304 bytes in 8 blocks
==19653==    still reachable: 289,073,104 bytes in 4,905 blocks
==19653==         suppressed: 0 bytes in 0 blocks
==19653== Rerun with --leak-check=full to see details of leaked memory
==19653== 
==19653== For counts of detected and suppressed errors, rerun with: -v
==19653== ERROR SUMMARY: 203 errors from 3 contexts (suppressed: 0 from 0)
[2]    19653 abort (core dumped)  valgrind bin/psi_phasing.exe -r 1 -n 100 -b 24

The last error is probably caused by the stash elements being read in 32-bit words, while they are only allocated using the number of bytes actually needed in cuckoo.cpp:128.
Reading and writing hashed elements byte-wise might fix this, however, I haven't managed to find all the places that would need to be changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant