summaryrefslogtreecommitdiffstats
path: root/crypto/context.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2021-01-08 13:22:59 +0000
committerMatt Caswell <matt@openssl.org>2021-01-14 17:30:46 +0000
commit2c40421440d260ddb97a807b064033f61ae3b2b3 (patch)
tree7ae85d1721e8b0331e324b62963ef7bd8bd27cec /crypto/context.c
parentc25a1524aad3a2f3a5d74880d8016de31f59adc8 (diff)
Make sure we take the ctx->lock in ossl_lib_ctx_generic_new()
The function ossl_lib_ctx_generic_new() modifies the exdata. This may be simultaneously being modified by other threads and therefore we need to make sure we take the lock before doing so. Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org> (Merged from https://github.com/openssl/openssl/pull/13660)
Diffstat (limited to 'crypto/context.c')
-rw-r--r--crypto/context.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/crypto/context.c b/crypto/context.c
index c351ff9619..953de5a489 100644
--- a/crypto/context.c
+++ b/crypto/context.c
@@ -228,10 +228,14 @@ static void ossl_lib_ctx_generic_new(void *parent_ign, void *ptr_ign,
long argl_ign, void *argp)
{
const OSSL_LIB_CTX_METHOD *meth = argp;
- void *ptr = meth->new_func(crypto_ex_data_get_ossl_lib_ctx(ad));
+ OSSL_LIB_CTX *ctx = crypto_ex_data_get_ossl_lib_ctx(ad);
+ void *ptr = meth->new_func(ctx);
- if (ptr != NULL)
+ if (ptr != NULL) {
+ CRYPTO_THREAD_write_lock(ctx->lock);
CRYPTO_set_ex_data(ad, index, ptr);
+ CRYPTO_THREAD_unlock(ctx->lock);
+ }
}
static void ossl_lib_ctx_generic_free(void *parent_ign, void *ptr,
CRYPTO_EX_DATA *ad, int index,