aboutsummaryrefslogtreecommitdiffstats
path: root/test/threadstest.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix typosDimitri Papadopoulos2026-07-081-6/+6
| | | | | | | | | | | | | | | | Found by typos[1]. [1] https://github.com/crate-ci/typos CLA: trivial Reviewed-by: Shane Lontis <[email protected]> Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tim Hudson <[email protected]> Reviewed-by: Norbert Pocs <[email protected]> Reviewed-by: Eugene Syromiatnikov <[email protected]> MergeDate: Wed Jul 8 10:46:01 2026 (Merged from https://github.com/openssl/openssl/pull/31858)
* Fix ignored call in ossl_rcu_call when cb item alloc failsJakub Zelenka2026-05-111-2/+9
| | | | | | | | | | | | | | | Currently when allocation of cb item fails, the actual cb function is not called. The is used just in hashtable when the cb function frees the old item which result in memory leak. To fix this, the allocation needs to be separated and happen before the assign operation is done. Reviewed-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> MergeDate: Mon May 11 08:21:55 2026 (Merged from https://github.com/openssl/openssl/pull/31092)
* Replace one missing snprint with BIO_snprintfMilan Broz2026-04-301-1/+1
| | | | | | | | | | Older compilers like MSVC 2013 do not support it. Reviewed-by: Eugene Syromiatnikov <[email protected]> Reviewed-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Paul Dale <[email protected]> MergeDate: Thu Apr 30 06:49:22 2026 (Merged from https://github.com/openssl/openssl/pull/31019)
* threadstest: Check the return value of two memory allocationsAditya Patil2026-03-241-2/+4
| | | | | | | | | | | Add a NULL check with OPENSSL_assert() before dereferencing the allocated pointer. Fixes #30017 Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Paul Dale <[email protected]> MergeDate: Tue Mar 24 17:44:44 2026 (Merged from https://github.com/openssl/openssl/pull/30509)
* 4.0-POST-CLANG-FORMAT-WEBKIT4.0-POST-CLANG-FORMAT-WEBKITBob Beck2025-12-091-110/+108
| | | | | | | Reviewed-by: Saša Nedvědický <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Nikola Pajkovsky <[email protected]> (Merged from https://github.com/openssl/openssl/pull/29242)
* clang deprecates sprintf on macosNikola Pajkovsky2025-10-211-1/+1
| | | | | | | | | | | | | | test/threadstest.c:1376:9: error: 'sprintf' is deprecated. The same issues is in the ossl-nghttp3-demo. Signed-off-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Saša Nedvědický <[email protected]> Reviewed-by: Richard Levitte <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Neil Horman <[email protected]> (Merged from https://github.com/openssl/openssl/pull/28903)
* Add a test for multi-threaded OBJ_createBernd Edlinger2025-09-251-0/+37
| | | | | | | | | | | | | After a successful OBJ_create the returned NID should be the same NID that is returned from OBJ_ln2nid and should not change any more, but after an unsuccessful OBJ_create, another thread must have created the object, therefore OBJ_ln2nid should not return NID_undef in that case. Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/28582)
* Fix logic errors in torture_rw_high/low testBernd Edlinger2025-09-171-4/+7
| | | | | | | | | "old" was never assigned anything and the first assignment to "*iterations" in the loop was superfluous. Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/28574)
* Add one more trace message to the torture_rcu_high testBernd Edlinger2025-09-101-1/+4
| | | | | | | | | | | | | | | | | | | | It is interesting that in the very rare cases, where this test failure has been observed so far, the rcu torture value went always backwards to 0. This could be either due to ossl_rcu_deref(&writer_ptr) returning NULL, or the initial value of "new = CRYPTO_zalloc(sizeof(uint64_t), NULL, 0)" still visible despite ossl_rcu_assign_ptr(&writer_ptr, &new) immediatley after the "*new = global_ctr++" statement. Add one additional trace message to find out what exactly happens here, when it happens again. Additionally, we do no longer initialize the new value to zero but something else, so it can also be detected. Related to #27267 Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/28487)
* Add a test for accessing an X509_STORE from multiple threadsMatt Caswell2025-08-211-1/+64
| | | | | | | | | Check we don't have any threading issues when accessing an X509_STORE simultaneously Reviewed-by: Saša Nedvědický <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/28198)
* Fix failure checking on rcu_read_lockNeil Horman2025-08-091-1/+7
| | | | | | | | | | | | | | | | | | | | | | during memfail testing: https://github.com/openssl/openssl/actions/runs/16794088536/job/47561223902 We get lots of test failures in ossl_rcu_read_lock. This occurs because we have a few cases in the read lock path that attempt mallocs, which, if they fail, trigger an assert or a silent failure, which isn't really appropriate. We should instead fail gracefully, by informing the caller that the lock failed, like we do for CRYPTO_THREAD_read_lock. Fortunately, these are all internal apis, so we can convert ossl_rcu_read_lock to return an int indicating success/failure, and fail gracefully during the test, rather than hitting an assert abort. Fixes openssl/project#1315 Reviewed-by: Paul Yang <[email protected]> Reviewed-by: Dmitry Belyavskiy <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from https://github.com/openssl/openssl/pull/28195)
* test: Silence warnings on Win64 buildsTomas Mraz2025-07-021-2/+2
| | | | | | Reviewed-by: Saša Nedvědický <[email protected]> Reviewed-by: Neil Horman <[email protected]> (Merged from https://github.com/openssl/openssl/pull/27806)
* Add a test to confirm that we can repeatedly create and destroy keysNeil Horman2025-06-061-0/+24
| | | | | | | Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Saša Nedvědický <[email protected]> (Merged from https://github.com/openssl/openssl/pull/27775)
* Copyright year updatesopenssl-machine2025-03-121-1/+1
| | | | | | Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Matt Caswell <[email protected]> Release: yes
* RCU: Ensure that qp's are actually retired in orderBernd Edlinger2025-03-051-1/+8
| | | | | | | | | | | | | The current retirement code for rcu qp's has a race condition, which can cause use-after-free errors, but only if more than 3 QPs are allocated, which is not the default configuration. This fixes an oversight in commit 5949918f9afa ("Rework and simplify RCU code") Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/26952)
* Re-enable RCU torture test on MACOSXBernd Edlinger2025-02-221-4/+0
| | | | | | | | | | | This test was disabled due to "Stochastic failures in the RCU test on MACOSX" by #23967, which sounds like an issue that is probably fixed now. Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/26834)
* Add test for releasing a shared EVP_PKEY across threadsTomas Mraz2024-12-101-0/+40
| | | | | | Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Richard Levitte <[email protected]> (Merged from https://github.com/openssl/openssl/pull/25664)
* Fix uses of `EVP_PKEY_Q_keygen` with `size_t` variadic argumentArtSin2024-11-051-1/+1
| | | | | | | | | | | Fix cases where `int` argument was passed instead of `size_t`. CLA: trivial Reviewed-by: Richard Levitte <[email protected]> Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/25857)
* threads_win: fix build error with VS2010 x86Georgi Valkov2024-07-011-0/+46
| | | | | | | | | | | | | | | | | | | | | | | | | InterlockedAnd64 and InterlockedAdd64 are not available on VS2010 x86. We already have implemented replacements for other functions, such as InterlockedOr64. Apply the same approach to fix the errors. A CRYPTO_RWLOCK rw_lock is added to rcu_lock_st. Replace InterlockedOr64 and InterlockedOr with CRYPTO_atomic_load and CRYPTO_atomic_load_int, using the existing design pattern. Add documentation and tests for the new atomic functions CRYPTO_atomic_add64, CRYPTO_atomic_and Fixes: libcrypto.lib(libcrypto-lib-threads_win.obj) : error LNK2019: unresolved external symbol _InterlockedAdd64 referenced in function _get_hold_current_qp libcrypto.lib(libcrypto-lib-threads_win.obj) : error LNK2019: unresolved external symbol _InterlockedOr referenced in function _get_hold_current_qp libcrypto.lib(libcrypto-lib-threads_win.obj) : error LNK2019: unresolved external symbol _InterlockedAnd64 referenced in function _update_qp libcrypto.lib(libcrypto-lib-threads_win.obj) : error LNK2019: unresolved external symbol _InterlockedOr64 referenced in function _ossl_synchronize_rcu Signed-off-by: Georgi Valkov <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/24405)
* Some minor nit corrections in the thread code for rcuNeil Horman2024-06-201-1/+1
| | | | | | | | | Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/24630) (cherry picked from commit d38d2642287ef9a22f20e662a19c217c227043a6)
* OSSL_LIB_CTX_load_config() must not be called concurrently on same libctxTomas Mraz2024-05-091-14/+0
| | | | | | | | The semantics of such concurrent call is not defined. Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Neil Horman <[email protected]> (Merged from https://github.com/openssl/openssl/pull/24275)
* test/threadstest.c: Add checks for CRYPTO_THREAD_lock_new()Jiasheng Jiang2024-05-061-0/+11
| | | | | | | | | | | | | Add checks for the return value of CRYPTO_THREAD_lock_new() in order to avoid Null pointer dereference. Fixes: 5f8b812931 ("Add locking to atomic operations in rw/rcu tests") Fixes: d0e1a0ae70 ("RCU lock implementation") Fixes: 71a04cfca0 ("Implement new multi-threading API") Signed-off-by: Jiasheng Jiang <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/24313)
* Fix potential divide by zero errorNeil Horman2024-04-241-2/+18
| | | | | | | | | | | | | | | | | | Coverity caught the following issues: 1591477 1591475 1591473 1591470 all of which are simmilar, in that they catch potential divide by zero in double values. It can't actually happen since the the threads which increment these counters don't exit until they reach non-zero values, but its easy to add the checks, so lets do that to ensure that we don't change something in the future that causes it. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from https://github.com/openssl/openssl/pull/23462)
* Make rcu_thread_key context-awareNeil Horman2024-04-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Currently, rcu has a global bit of data, the CRYPTO_THREAD_LOCAL object to store per thread data. This works in some cases, but fails in FIPS, becuase it contains its own copy of the global key. So 1) Make the rcu_thr_key a per-context variable, and force ossl_rcu_lock_new to be context aware 2) Store a pointer to the context in the lock object 3) Use the context to get the global thread key on read/write lock 4) Use ossl_thread_start_init to properly register a cleanup on thread exit 5) Fix up missed calls to OSSL_thread_stop() in our tests Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Matt Caswell <[email protected]> (Merged from https://github.com/openssl/openssl/pull/24162)
* Copyright year updatesRichard Levitte2024-04-091-1/+1
| | | | | | | | | | Reviewed-by: Neil Horman <[email protected]> Release: yes (cherry picked from commit 0ce7d1f355c1240653e320a3f6f8109c1f05f8c0) Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/24034)
* Add locking to atomic operations in rw/rcu testsNeil Horman2024-04-021-8/+13
| | | | | | | | | | | | | | | | I neglected to add locks to the calls to CRYPTO_atomic_add in these test, which on newer compilers is fine, as atomic operations are defined. However on older compilers the __ATOMIC_ACQ_REL definition is missing causing these function to be implemented using an rwlock, which when NULL causes the locks to fail. Fix this my creating the lock and using them appropriately Fixes #24000 Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from https://github.com/openssl/openssl/pull/24001)
* Fix threadstest wrapping againNeil Horman2024-03-261-2/+6
| | | | | | | | | Stochastic failures in the RCU test on MACOSX are occuring. Due to beta release, disabling this test on MACOSX until post 3.3 release Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Matt Caswell <[email protected]> (Merged from https://github.com/openssl/openssl/pull/23967)
* Make counters in rcu/rw threads torture test 64 bitNeil Horman2024-03-221-8/+8
| | | | | | | | | | Its possible in some conditions for the rw/rcu torture tests to wrap the counter, leading to false positive failures, make them 64 bits to avoid this Reviewed-by: Shane Lontis <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/23724)
* RCU lock implementationNeil Horman2024-02-011-0/+376
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Introduce an RCU lock implementation as an alternative locking mechanism to openssl. The api is documented in the ossl_rcu.pod file Read side implementaiton is comparable to that of RWLOCKS: ossl_rcu_read_lock(lock); < critical section in which data can be accessed via ossl_derefrence > ossl_rcu_read_unlock(lock); Write side implementation is: ossl_rcu_write_lock(lock); < critical section in which data can be updated via ossl_assign_pointer and stale data can optionally be scheduled for removal via ossl_rcu_call > ossl_rcu_write_unlock(lock); ... ossl_synchronize_rcu(lock); ossl_rcu_call fixup Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Matt Caswell <[email protected]> (Merged from https://github.com/openssl/openssl/pull/22729)
* Copyright year updatesMatt Caswell2023-09-071-1/+1
| | | | | Reviewed-by: Richard Levitte <[email protected]> Release: yes
* Test loading a PEM file from multiple threadsMatt Caswell2023-07-171-0/+52
| | | | | | | | | The new decoder optimisation has some locking involved so we confirm that reading a PEM file from multiple threads works as expected. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from https://github.com/openssl/openssl/pull/21426)
* Split out thread pool tests into threadpool_testTomas Mraz2022-11-221-287/+0
| | | | | | Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from https://github.com/openssl/openssl/pull/19695)
* crypto: thread: remove ossl_crypto_thread_native_terminateČestmír Kalina2022-10-211-32/+1
| | | | | | | | Signed-off-by: Čestmír Kalina <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from https://github.com/openssl/openssl/pull/19473)
* test: threads: replace test_thread_noreturnČestmír Kalina2022-10-211-23/+8
| | | | | | | | | | | | | | | | | | | | | | | | While POSIX threads are cancellable and may be asynchronously cancelled, their cancellation is not guaranteed by the POSIX standard. test_thread_noreturn, which simulates a long-running possibly unresponsive thread: THREAD #1 THREAD #2 LOCK L1 SPAWN #2 LOCK L1 On MacOS, cancelling such thread only queues cancellation request, but the following pthread_join hangs. Replace this implementation by an unbounded sequence of sleeps instead. Signed-off-by: Čestmír Kalina <[email protected]> Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/19433)
* crypto: thread: serialize concurrent joinsČestmír Kalina2022-10-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Multiple concurrent joins with a running thread suffer from a race condition that allows concurrent join calls to perform concurrent arch specific join calls, which is UB on POSIX, or to concurrently execute join and terminate calls. As soon as a thread T1 exists, one of the threads that joins with T1 is selected to perform the join, the remaining ones await completion. Once completed, the remaining calls immediately return. If the join failed, another thread is selected to attempt the join operation. Forcefully terminating a thread that is in the process of joining another thread is not supported. Common code from thread_posix and thread_win was refactored to use common wrapper that handles synchronization. Signed-off-by: Čestmír Kalina <[email protected]> Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/19433)
* crypto: add preemptive threading supportČestmír Kalina2022-10-171-0/+333
| | | | | | | | | | | | | | | | | | | | | Some primitives are designed to be used in a multi-threaded environment, if supported, e.g., Argon2. This patch adds support for preemptive threading and basic synchronization primitives for platforms compliant with POSIX threads or Windows CRT. Native functions are wrapped to provide a common (internal) API. Threading support can be disabled at compile time. If enabled, threading is disabled by default and needs to be explicitly enabled by the user. Thread enablement requires an explicit limit on the number of threads that OpenSSL may spawn (non-negative integer/infinity). The limit may be changed. Signed-off-by: Čestmír Kalina <[email protected]> Reviewed-by: Hugo Landau <[email protected]> Reviewed-by: Matt Caswell <[email protected]> (Merged from https://github.com/openssl/openssl/pull/12255)
* BIO_s_dgram_pairHugo Landau2022-09-231-8/+89
| | | | | | Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from https://github.com/openssl/openssl/pull/18442)
* Make OSSL_LIB_CTX_load_config thread safeHugo Landau2022-06-011-0/+14
| | | | | | | | | Fixes #18226. Reviewed-by: Matt Caswell <[email protected]> Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/18331)
* Update copyright yearMatt Caswell2022-05-031-1/+1
| | | | | Reviewed-by: Tomas Mraz <[email protected]> Release: yes
* threadstest: use locking for tsan operations if requiredPauli2022-01-131-2/+26
| | | | | | | | | | Not all platforms support tsan operations, those that don't need to have an alternative locking path. Fixes #17447 Reviewed-by: Bernd Edlinger <[email protected]> (Merged from https://github.com/openssl/openssl/pull/17479)
* threadstest: add write check to lock checkingPauli2022-01-131-0/+2
| | | | | Reviewed-by: Bernd Edlinger <[email protected]> (Merged from https://github.com/openssl/openssl/pull/17479)
* Fix EVP_PKEY_decrypt return checkPeiwei Hu2021-11-221-2/+3
| | | | | | Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/17028)
* Extend the test_multi_load() testMatt Caswell2021-11-121-3/+19
| | | | | | | | Run more threads and load the legacy provider (which uses a child lib ctx) in order to hit more possible thread failures. Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/16980)
* test: add threading test for object creationPauli2021-09-251-140/+232
| | | | | | | In addition, rework the multi tests to use common code. Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/15713)
* test: fix test ordering in threads testPauli2021-06-301-14/+28
| | | | | | | Fixes #15953 Reviewed-by: Tomas Mraz <[email protected]> (Merged from https://github.com/openssl/openssl/pull/15954)
* Always wait for both threads to finishRich Salz2021-06-161-5/+9
| | | | | | | Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Richard Levitte <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from https://github.com/openssl/openssl/pull/15708)
* test: fix typo in comment in threadstest.cPauli2021-05-241-1/+1
| | | | | Reviewed-by: Matt Caswell <[email protected]> (Merged from https://github.com/openssl/openssl/pull/15278)
* test: add test case to reliably reproduce RAND leak during POSTPauli2021-05-241-66/+1
| | | | | | | | The FIPS provider leaks a RAND if the POST is run at initialisation time. This test case reliably reproduces this event. Reviewed-by: Matt Caswell <[email protected]> (Merged from https://github.com/openssl/openssl/pull/15278)
* test: fix thread test config file problemPauli2021-05-131-4/+11
| | | | | | | | | | Force the thread test to use the configuration file via a command line arg. Use the test library support for libctx creation. Fixes #15243 Reviewed-by: Shane Lontis <[email protected]> (Merged from https://github.com/openssl/openssl/pull/15256)
* Add convenience functions and macros for asymmetric key generationDr. David von Oheimb2021-05-111-15/+8
| | | | | | | | | Add EVP_PKEY_gen(), EVP_PKEY_Q_gen(), EVP_RSA_gen(), and EVP_EC_gen(). Also export auxiliary function OSSL_EC_curve_nid2name() and improve deprecation info on RSA and EC key generation/management functions. Reviewed-by: Shane Lontis <[email protected]> (Merged from https://github.com/openssl/openssl/pull/14695)