openssl / openssl

TLS/SSL and crypto library
https://www.openssl.org
Apache License 2.0
25.81k stars 10.13k forks source link

openssl-3.0: ssl_module_init() + ssl_module_free() is not serialized. #19243

Open sebastianas opened 2 years ago

sebastianas commented 2 years ago

The ssl_module_init() + ssl_module_free() are not serialized when called from multiplie threads. This has been more visible after adding CipherString to test/default.cnf and running threadstest in a loop. It segfaults between 1 and 20 iterations:

./test/threadstest -config ../test/default.cnf ../test/recipes/90-test_threads_data
1..8  
ok 1 - test_multi_default
ok 2 - test_lock
ok 3 - test_once
ok 4 - test_thread_local
ok 5 - test_atomic
ok 6 - test_multi_load
    # Subtest: test_multi
    1..6
    ok 1 - iteration 1
    # SKIP:  @ ../test/threadstest.c:480
    # FIPS not supported
    ok 2 - iteration 2 # skipped
    ok 3 - iteration 3
    ok 4 - iteration 4
    ok 5 - iteration 5
    ok 6 - iteration 6
ok 7 - test_multi
Segmentation fault      (core dumped) ./test/threadstest -config ../test/default.cnf ../test/recipes/90-test_threads_data
~$ gdb ./test/threadstest ./core
GNU gdb (Debian 12.1-3) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test/threadstest...
[New LWP 337618]
[New LWP 337589]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./test/threadstest -config ../test/default.cnf ../test/recipes/90-test_threads_'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007fc1ad49674a in __GI___libc_free (mem=0x491a3de0b958d4b7) at ./malloc/malloc.c:3251
3251    ./malloc/malloc.c: No such file or directory.
[Current thread is 1 (Thread 0x7fc1ad3fe640 (LWP 337618))]
(gdb) bt
#0  0x00007fc1ad49674a in __GI___libc_free (mem=0x491a3de0b958d4b7) at ./malloc/malloc.c:3251
#1  0x00007fc1ad75870d in ssl_module_free (md=<optimized out>) at ../crypto/conf/conf_ssl.c:54
#2  0x00007fc1ad7587cd in ssl_module_free (md=<optimized out>) at ../crypto/conf/conf_ssl.c:44
#3  ssl_module_init (md=<optimized out>, cnf=0x7fc188000f40) at ../crypto/conf/conf_ssl.c:80
#4  0x00007fc1ad757ba1 in module_init (cnf=0x7fc188000f40, value=0x7fc1880029a0 "ssl_sect", name=0x7fc188002950 "ssl_conf", pmod=0x5643bab20f60) at ../crypto/conf/conf_mod.c:421
#5  module_run (flags=0, value=0x7fc1880029a0 "ssl_sect", name=0x7fc188002950 "ssl_conf", cnf=0x7fc188000f40) at ../crypto/conf/conf_mod.c:266
#6  CONF_modules_load (cnf=cnf@entry=0x7fc188000f40, appname=appname@entry=0x0, flags=flags@entry=0) at ../crypto/conf/conf_mod.c:165
#7  0x00007fc1ad758280 in CONF_modules_load_file_ex (libctx=<optimized out>, filename=0x7ffca4ccf765 "../test/default.cnf", appname=appname@entry=0x0, flags=flags@entry=0)
    at ../crypto/conf/conf_mod.c:208
#8  0x00007fc1ad82a82d in OSSL_LIB_CTX_load_config (ctx=<optimized out>, config_file=<optimized out>) at ../crypto/context.c:236
#9  0x00005643b9522a97 in test_lib_ctx_load_config_worker () at ../test/threadstest.c:655
#10 0x00005643b9522a56 in thread_run (arg=<optimized out>) at ../test/threadstest.h:67
#11 0x00007fc1ad486b27 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:435
#12 0x00007fc1ad50978c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
(gdb) thread 2
[Switching to thread 2 (Thread 0x7fc1adc3a740 (LWP 337589))]
#0  0x00007fc1ad487775 in allocate_stack (stacksize=<synthetic pointer>, stack=<synthetic pointer>, pdp=<synthetic pointer>, attr=0x7ffca4ccc220) at ./nptl/allocatestack.c:416
416     ./nptl/allocatestack.c: No such file or directory.
(gdb) bt
#0  0x00007fc1ad487775 in allocate_stack (stacksize=<synthetic pointer>, stack=<synthetic pointer>, pdp=<synthetic pointer>, attr=0x7ffca4ccc220) at ./nptl/allocatestack.c:416
#1  __pthread_create_2_1 (newthread=0x5643b9534170 <multi_threads+48>, attr=attr@entry=0x0, start_routine=start_routine@entry=0x5643b9522a50 <thread_run>,
    arg=arg@entry=0x5643b9522a80 <test_lib_ctx_load_config_worker>) at ./nptl/pthread_create.c:631
#2  0x00005643b95243f1 in run_thread (f=0x5643b9522a80 <test_lib_ctx_load_config_worker>, t=<optimized out>) at ../test/threadstest.h:73
#3  start_threads (n=10, thread_func=0x5643b9522a80 <test_lib_ctx_load_config_worker>) at ../test/threadstest.c:279
#4  thread_run_test (main_func=0x5643b9522a80 <test_lib_ctx_load_config_worker>, num_threads=10, thread_func=0x5643b9522a80 <test_lib_ctx_load_config_worker>, libctx=1,
    providers=0x5643b9534020 <default_provider>) at ../test/threadstest.c:293
#5  test_lib_ctx_load_config () at ../test/threadstest.c:661
#6  0x00005643b9527004 in run_tests (test_prog_name=<optimized out>) at ../test/testutil/driver.c:334
#7  0x00005643b952291b in main (argc=4, argv=0x7ffca4ccd558) at ../test/testutil/main.c:30
mattcaswell commented 2 years ago

See also #19248 which reports a different but related problem.

nhorman commented 4 months ago

marking as inactive, will be closed at the end of the 3.4 dev cycle barring further input

sebastianas commented 1 week ago

This issue has been closed "barring further input" but I was not aware that I need to provide further input. This kind moved to #19248 and then stalled. I carry that patch ever since in Debian.

nhorman commented 3 days ago

@t8m why did you reopen this? As @sebastianas indicated, this seems to have moved to #19248, which is where further discussions an OTC decisions have taken place in the intervening time. I see no need to keep this open if we have another issue where this same topic is being discussed.

t8m commented 3 days ago

19248 is related but not the same issue. IMO the issue of OSSL_LIB_CTX_load_config not being thread safe with some configuration files is separate.