diff options
author | Matt Caswell <matt@openssl.org> | 2021-01-26 17:00:25 +0000 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2021-02-02 12:21:21 +0000 |
commit | 04b9435a991585d0f9a775a203cc3986d4872a6e (patch) | |
tree | 745fdbd73fab4b9c3bfb27af89e276ea46710f63 /crypto/ex_data.c | |
parent | b233ea82765e80038e4884564153f9c8543d9396 (diff) | |
download | openssl-new-04b9435a991585d0f9a775a203cc3986d4872a6e.tar.gz |
Always ensure we hold ctx->lock when calling CRYPTO_get_ex_data()
Otherwise we can get data races.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13987)
Diffstat (limited to 'crypto/ex_data.c')
-rw-r--r-- | crypto/ex_data.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/crypto/ex_data.c b/crypto/ex_data.c index 5de99b4735..0d87ea7f0e 100644 --- a/crypto/ex_data.c +++ b/crypto/ex_data.c @@ -392,16 +392,23 @@ void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) int CRYPTO_alloc_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad, int idx) { - EX_CALLBACK *f; - EX_CALLBACKS *ip; void *curval; - OSSL_EX_DATA_GLOBAL *global; curval = CRYPTO_get_ex_data(ad, idx); /* Already there, no need to allocate */ if (curval != NULL) return 1; + return ossl_crypto_alloc_ex_data_intern(class_index, obj, ad, idx); +} + +int ossl_crypto_alloc_ex_data_intern(int class_index, void *obj, + CRYPTO_EX_DATA *ad, int idx) +{ + EX_CALLBACK *f; + EX_CALLBACKS *ip; + OSSL_EX_DATA_GLOBAL *global; + global = ossl_lib_ctx_get_ex_data_global(ad->ctx); if (global == NULL) return 0; |