bin/51205: openssl in base system is not compiled thread safe
jwestfall at surrealistic.net
Mon Apr 21 00:40:20 PDT 2003
>Synopsis: openssl in base system is not compiled thread safe
>Arrival-Date: Mon Apr 21 00:40:18 PDT 2003
>Originator: Jim Westfall
>Release: FreeBSD 4.6.2-RELEASE-p13 i386
System: FreeBSD snapper.surrealistic.net 4.6.2-RELEASE-p13 FreeBSD 4.6.2-RELEASE-p13 #10: Sat Mar 29 13:46:35 PST 2003 root at snapper.surrealistic.net:/usr/obj/usr/src/sys/SMP_46 i386
FreeBSD ultrax.surrealistic.net 4.8-RELEASE FreeBSD 4.8-RELEASE #2: Mon Apr 7 16:01:24 PDT 2003 root at ultrax.surrealistic.net:/usr/obj/usr/src/sys/UP_48 i386
openssl thats included in the base system is not being compiled with the necessary CFLAGS to make
it thread safe. Because of this its possible to cause an assertion failure within libcrypto if multiple threads
are accessing RAND_add() function call at the same time. RAND_add() is called by both SSL_connect() and
SSL_accept() functions. So if multiple threads are calling either of these function it can trigger the
assertion. I can easily reproduce the assertion with an threaded ftp client i have been working on. It can
also be tiggerred with a small mod to mttest.c, which is the thread test program thats include in the openssl
it can be a bit tricky to reproduce the error, but the following patch applied to mttest.c adds
a RAND_add() call to stress the function in hopes of causing the assertion. mttest.c is located at
--- mttest.old.c Sun Apr 20 22:36:45 2003
+++ mttest.c Mon Apr 21 00:07:02 2003
@@ -354,6 +354,7 @@
@@ -379,7 +380,7 @@
fprintf(stdout,"error[%d] %lu - %d\n",
@@ -407,6 +408,7 @@
+ time_t Time = time(NULL);
@@ -448,6 +450,7 @@
/* We can always do writes */
+ RAND_add(&Time, sizeof(Time), 0);
[root at ultrax]# patch -p0 < mttest.patch
Hmm... Looks like a unified diff to me...
The text leading up to this was:
|--- mttest.old.c Sun Apr 20 22:36:45 2003
|+++ mttest.c Mon Apr 21 00:07:02 2003
Patching file mttest.c using Plan A...
Hunk #1 succeeded at 354.
Hunk #2 succeeded at 380.
Hunk #3 succeeded at 408.
Hunk #4 succeeded at 450.
[root at ultrax]# gcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto -pthread
[root at ultrax]# ./mttest -CAfile /etc/ssl/certs/ftpd.pem -threads 100 -loops 100 -client_auth -ssl3 2>&1 | grep -vi error | grep -v started
assertion "md_c == md_count" failed: file "/usr/src/secure/lib/libcrypto/../../../crypto/openssl/crypto/rand/md_rand.c", line 312
this is the particular assertion in md_rand.c (0.9.7a)
#if !defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32)
assert(md_c == md_count);
I believe its just an oversite. based on /usr/src/secure/lib/libcrypto/opensslconf-i386.h which is
auto-generated, it shows that openssl has been configured to have thread support. It just that the necessary
CFLAGS where not updated in src/secure/lib/libcrypto/Makefile.inc. It appears its been like this for a while as
my 4.6.2 machine is effected too. I havent looked at 5.0 is see if it is as well.
The fix depends on which openssl version is installed.
-DOPENSSL_THREADS -pthread -D_REENTRANT -D_THREAD_SAFE -D_THREADSAFE
-DTHREADS -pthread -D_REENTRANT -D_THREAD_SAFE -D_THREADSAFE
More information about the freebsd-bugs