diff options
author | Neil Horman <nhorman@openssl.org> | 2024-04-15 16:56:29 -0400 |
---|---|---|
committer | Neil Horman <nhorman@openssl.org> | 2024-04-19 09:22:53 -0400 |
commit | 24d16d3a1915a06a2130385a87de9a37fc09c4b9 (patch) | |
tree | 2add2328ebad114d63abcc440f0cbf3325eda44b /include | |
parent | faa4a10ebe5095765262c0e3c711fca08026c3d4 (diff) |
Make rcu_thread_key context-aware
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 <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24162)
Diffstat (limited to 'include')
-rw-r--r-- | include/internal/cryptlib.h | 1 | ||||
-rw-r--r-- | include/internal/rcu.h | 4 |
2 files changed, 4 insertions, 1 deletions
diff --git a/include/internal/cryptlib.h b/include/internal/cryptlib.h index 64851fd8ed..6c2ac47275 100644 --- a/include/internal/cryptlib.h +++ b/include/internal/cryptlib.h @@ -130,6 +130,7 @@ void ossl_lib_ctx_default_deinit(void); OSSL_EX_DATA_GLOBAL *ossl_lib_ctx_get_ex_data_global(OSSL_LIB_CTX *ctx); const char *ossl_lib_ctx_get_descriptor(OSSL_LIB_CTX *libctx); +CRYPTO_THREAD_LOCAL *ossl_lib_ctx_get_rcukey(OSSL_LIB_CTX *libctx); OSSL_LIB_CTX *ossl_crypto_ex_data_get_ossl_lib_ctx(const CRYPTO_EX_DATA *ad); int ossl_crypto_new_ex_data_ex(OSSL_LIB_CTX *ctx, int class_index, void *obj, diff --git a/include/internal/rcu.h b/include/internal/rcu.h index 7716a1c7f2..90160e8da7 100644 --- a/include/internal/rcu.h +++ b/include/internal/rcu.h @@ -11,11 +11,13 @@ # define OPENSSL_RCU_H # pragma once +#include "crypto/context.h" + typedef void (*rcu_cb_fn)(void *data); typedef struct rcu_lock_st CRYPTO_RCU_LOCK; -CRYPTO_RCU_LOCK *ossl_rcu_lock_new(int num_writers); +CRYPTO_RCU_LOCK *ossl_rcu_lock_new(int num_writers, OSSL_LIB_CTX *ctx); void ossl_rcu_lock_free(CRYPTO_RCU_LOCK *lock); void ossl_rcu_read_lock(CRYPTO_RCU_LOCK *lock); void ossl_rcu_write_lock(CRYPTO_RCU_LOCK *lock); |