From 4b1f34f11ff94bc2d0169d6669bfc47f99bd93b3 Mon Sep 17 00:00:00 2001 From: Pauli Date: Wed, 7 Apr 2021 11:32:59 +1000 Subject: property: lock the lib ctx when updating the property definition cache Although the store being used is adequately and properly locked, the library context is not. Due to the mechanisms used for fetching, it is possible for multiple stores to live within the same library context for short periods. This fix prevents threading issues resulting from such coincidences. Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/14773) --- crypto/context.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crypto/context.c') diff --git a/crypto/context.c b/crypto/context.c index 852f9dd7ce..6c088e6628 100644 --- a/crypto/context.c +++ b/crypto/context.c @@ -11,6 +11,7 @@ #include #include "internal/thread_once.h" #include "internal/property.h" +#include "internal/core.h" struct ossl_lib_ctx_onfree_list_st { ossl_lib_ctx_onfree_fn *fn; @@ -39,6 +40,21 @@ struct ossl_lib_ctx_st { struct ossl_lib_ctx_onfree_list_st *onfreelist; }; +int ossl_lib_ctx_write_lock(OSSL_LIB_CTX *ctx) +{ + return CRYPTO_THREAD_write_lock(ossl_lib_ctx_get_concrete(ctx)->lock); +} + +int ossl_lib_ctx_read_lock(OSSL_LIB_CTX *ctx) +{ + return CRYPTO_THREAD_read_lock(ossl_lib_ctx_get_concrete(ctx)->lock); +} + +int ossl_lib_ctx_unlock(OSSL_LIB_CTX *ctx) +{ + return CRYPTO_THREAD_unlock(ossl_lib_ctx_get_concrete(ctx)->lock); +} + static int context_init(OSSL_LIB_CTX *ctx) { size_t i; -- cgit v1.2.1