_gcry_ath_mutex_lock in GnuTLS
Rich Fought
whatever at fsrz.net
Tue Jan 17 00:47:53 CET 2006
Hello everyone,
I hope someone may be able to help me out here.
I've got a multi-threaded server-type application using GnuTLS 1.2.9 and
libgcrypt 1.2.2.
Usually after about 5-10 minutes of hammering on it with simultaneous
connections,
I'm getting the dreaded
ath.c:184: _gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)'
failed.
which tells me that perhaps libgcrypt is not being initialized properly
for thread
safety. Almost always this happens when two handshakes are happening
concurrently.
However, there are complicating factors.
1) I am using Haskell bindings to GnuTLS through foreign functions
calls/imports
(hsgnutls). There is an initilization routine being completed at the
topmost level
before any threads are being created (which looks OK given what I've
found on the net)
and the call to gnutls_global_init:
GCRY_THREAD_OPTION_PTHREAD_IMPL;
void gcry_init_helper(void) {
gcry_control(GCRYCTL_DISABLE_SECMEM_WARN);
gcry_control(GCRYCTL_INIT_SECMEM, 16384, 0);
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
}
Does this look OK?
2) These initialization functions (gcry_init_helper and
gnutls_global_init) are also
called with every new session creation in the Haskell bindings. I
thought this was odd,
but from what I've found this is not unheard of. gnutls_global_init
should be fine,
but what about gcry_init_helper? Shouldn't libgcrypt initialization only
be done once?
3) The Haskell (Glasgow Haskell Compiler, to be specific) runtime
threading model is a
mix of Haskell light threads (for lack of a better term) running in the
same single OS
thread, and actual OS threads depending on how they are forked (and if
any foreign calls
are in the thread). I've made sure that all threads handling TLS
handshakes are bound to
dedicated OS threads (pthreads, BTW). The error still persists.
Perhaps all threads that
access any libgcrypt library functions should be bound so?
A gdb dump is attached.
TIA,
Rich
-------------------------------------------
ath.c:184: _gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)'
failed.
Program received signal SIGABRT, Aborted.
[Switching to Thread 1933321 (LWP 22018)]
0x005d5bd1 in kill () from /lib/i686/libc.so.6
Thread 120 (Thread 1933321 (LWP 22018)):
#0 0x005d5bd1 in kill () from /lib/i686/libc.so.6
#1 0x00433251 in pthread_kill () from /lib/i686/libpthread.so.0
#2 0x004335bb in raise () from /lib/i686/libpthread.so.0
#3 0x005d5838 in raise () from /lib/i686/libc.so.6
#4 0x005d6e80 in abort () from /lib/i686/libc.so.6
#5 0x005ce821 in __assert_fail () from /lib/i686/libc.so.6
#6 0x00119449 in _gcry_ath_mutex_lock (lock=0x157908) at ath.c:180
#7 0x0011d880 in gcry_pk_decrypt (r_plain=0x2b68c4c, s_data=0x82e33a0,
s_skey=0x82e35d8) at pubkey.c:1502
#8 0x00b2b101 in _gnutls_pk_decrypt () from /usr/local/lib/libgnutls.so.12
#9 0x00b2a0ba in _gnutls_pkcs1_rsa_decrypt () from
/usr/local/lib/libgnutls.so.12
#10 0x00b2803a in _gnutls_proc_rsa_client_kx () from
/usr/local/lib/libgnutls.so.12
#11 0x00b2166f in _gnutls_recv_client_kx_message () from
/usr/local/lib/libgnutls.so.12
#12 0x00b1dc90 in _gnutls_handshake_server () from
/usr/local/lib/libgnutls.so.12
#13 0x00b1c696 in gnutls_handshake () from /usr/local/lib/libgnutls.so.12
#14 0x0818f4ac in rbbY_info ()
#15 0xb7e2e5c0 in ?? ()
#16 0x00000000 in ?? ()
Thread 119 (Thread 1916936 (LWP 22014)):
#0 0x004321b0 in pthread_handle_sigrestart () from
/lib/i686/libpthread.so.0
#1 <signal handler called>
#2 0x004330d4 in __pthread_sigsuspend () from /lib/i686/libpthread.so.0
#3 0x00432708 in __pthread_wait_for_restart_signal () from
/lib/i686/libpthread.so.0
#4 0x00434720 in __pthread_alt_lock () from /lib/i686/libpthread.so.0
#5 0x0043114e in pthread_mutex_lock () from /lib/i686/libpthread.so.0
#6 0x0060fe53 in free () from /lib/i686/libc.so.6
#7 0x00115dbc in gcry_free (p=0x438ff4) at global.c:487
#8 0x00148248 in _gcry_mpi_free_limb_space (a=0x8, nlimbs=4294967292)
at mpiutil.c:102
#9 0x0014835d in _gcry_mpi_free (a=0xb7e23990) at mpiutil.c:158
#10 0x001438bd in gcry_mpi_sub (w=0xb7e06070, u=0xb7e101c0,
v=0xb7e1c658) at mpi-add.c:219
#11 0x001449d1 in _gcry_mpi_invm (x=0xb7e11640, a=0xb7e26260,
n=0xb7e357f8) at mpi-inv.c:242
#12 0x00144cb5 in gcry_mpi_invm (x=0xb7e11640, a=0xb7e26260,
n=0xb7e357f8) at mpi-inv.c:273
#13 0x0013a46d in _gcry_rsa_decrypt (algo=1, result=0xfffffffc,
data=0xb7e291a0, skey=0x438ff4, flags=0) at rsa.c:531
#14 0x0011bfb2 in pubkey_decrypt (algorithm=1, result=0x5478bf8,
data=0xb7e291a0, skey=0xb7e570b0, flags=0) at pubkey.c:594
#15 0x0011d9fc in gcry_pk_decrypt (r_plain=0x5478c4c, s_data=0xb7e58880,
s_skey=0xb7e05e20) at pubkey.c:1521
#16 0x00b2b101 in _gnutls_pk_decrypt () from /usr/local/lib/libgnutls.so.12
#17 0x00b2a0ba in _gnutls_pkcs1_rsa_decrypt () from
/usr/local/lib/libgnutls.so.12
#18 0x00b2803a in _gnutls_proc_rsa_client_kx () from
/usr/local/lib/libgnutls.so.12
#19 0x00b2166f in _gnutls_recv_client_kx_message () from
/usr/local/lib/libgnutls.so.12
#20 0x00b1dc90 in _gnutls_handshake_server () from
/usr/local/lib/libgnutls.so.12
#21 0x00b1c696 in gnutls_handshake () from /usr/local/lib/libgnutls.so.12
#22 0x0818f4ac in rbbY_info ()
#23 0xb7e30a28 in ?? ()
#24 0x00000000 in ?? ()
Thread 118 (Thread 1900552 (LWP 21959)):
#0 0x004321b0 in pthread_handle_sigrestart () from
/lib/i686/libpthread.so.0
#1 <signal handler called>
#2 0x004330d4 in __pthread_sigsuspend () from /lib/i686/libpthread.so.0
#3 0x00432708 in __pthread_wait_for_restart_signal () from
/lib/i686/libpthread.so.0
#4 0x00434720 in __pthread_alt_lock () from /lib/i686/libpthread.so.0
#5 0x0043114e in pthread_mutex_lock () from /lib/i686/libpthread.so.0
#6 0x0060fe53 in free () from /lib/i686/libc.so.6
#7 0x00115dbc in gcry_free (p=0x438ff4) at global.c:487
#8 0x00148248 in _gcry_mpi_free_limb_space (a=0x8, nlimbs=4294967292)
at mpiutil.c:102
#9 0x0014835d in _gcry_mpi_free (a=0xb7e23990) at mpiutil.c:158
#10 0x001438bd in gcry_mpi_sub (w=0xb7e06070, u=0xb7e101c0,
v=0xb7e1c658) at mpi-add.c:219
#11 0x001449d1 in _gcry_mpi_invm (x=0xb7e11640, a=0xb7e26260,
n=0xb7e357f8) at mpi-inv.c:242
#12 0x00144cb5 in gcry_mpi_invm (x=0xb7e11640, a=0xb7e26260,
n=0xb7e357f8) at mpi-inv.c:273
#13 0x0013a46d in _gcry_rsa_decrypt (algo=1, result=0xfffffffc,
data=0xb7e291a0, skey=0x438ff4, flags=0) at rsa.c:531
#14 0x0011bfb2 in pubkey_decrypt (algorithm=1, result=0x5478bf8,
data=0xb7e291a0, skey=0xb7e570b0, flags=0) at pubkey.c:594
#15 0x0011d9fc in gcry_pk_decrypt (r_plain=0x5478c4c, s_data=0xb7e58880,
s_skey=0xb7e05e20) at pubkey.c:1521
#16 0x00b2b101 in _gnutls_pk_decrypt () from /usr/local/lib/libgnutls.so.12
#17 0x00b2a0ba in _gnutls_pkcs1_rsa_decrypt () from
/usr/local/lib/libgnutls.so.12
#18 0x00b2803a in _gnutls_proc_rsa_client_kx () from
/usr/local/lib/libgnutls.so.12
#19 0x00b2166f in _gnutls_recv_client_kx_message () from
/usr/local/lib/libgnutls.so.12
#20 0x00b1dc90 in _gnutls_handshake_server () from
/usr/local/lib/libgnutls.so.12
#21 0x00b1c696 in gnutls_handshake () from /usr/local/lib/libgnutls.so.12
#22 0x0818f4ac in rbbY_info ()
#23 0xb7e30a28 in ?? ()
#24 0x00000000 in ?? ()
More information about the Gcrypt-devel
mailing list