summaryrefslogtreecommitdiffstats
path: root/crypto/provider.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2021-06-22 15:39:40 +0100
committerMatt Caswell <matt@openssl.org>2021-06-24 14:48:15 +0100
commit59a783d05ae379335f70261126d19859ae5a855d (patch)
treee53202714c18129c1fd24b5bbf409bc0f6a60443 /crypto/provider.c
parentd382c4652570766fc7a9ccfc63e7a62aea3d5bcb (diff)
Fix a race in ossl_provider_add_to_store()
If two threads both attempt to load the same provider at the same time, they will first both check to see if the provider already exists. If it doesn't then they will both then create new provider objects and call the init function. However only one of the threads will be successful in adding the provider to the store. For the "losing" thread we should still return "success", but we should deinitialise and free the no longer required provider object, and return the object that exists in the store. Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15854)
Diffstat (limited to 'crypto/provider.c')
-rw-r--r--crypto/provider.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/crypto/provider.c b/crypto/provider.c
index c8db329837..82d980a8ae 100644
--- a/crypto/provider.c
+++ b/crypto/provider.c
@@ -18,7 +18,7 @@
OSSL_PROVIDER *OSSL_PROVIDER_try_load(OSSL_LIB_CTX *libctx, const char *name,
int retain_fallbacks)
{
- OSSL_PROVIDER *prov = NULL;
+ OSSL_PROVIDER *prov = NULL, *actual;
int isnew = 0;
/* Find it or create it */
@@ -33,13 +33,14 @@ OSSL_PROVIDER *OSSL_PROVIDER_try_load(OSSL_LIB_CTX *libctx, const char *name,
return NULL;
}
- if (isnew && !ossl_provider_add_to_store(prov, retain_fallbacks)) {
+ actual = prov;
+ if (isnew && !ossl_provider_add_to_store(prov, &actual, retain_fallbacks)) {
ossl_provider_deactivate(prov);
ossl_provider_free(prov);
return NULL;
}
- return prov;
+ return actual;
}
OSSL_PROVIDER *OSSL_PROVIDER_load(OSSL_LIB_CTX *libctx, const char *name)