]> granicus.if.org Git - openssl/commitdiff
Avoid holding a lock when calling OPENSSL_init_crypto
authorMatt Caswell <matt@openssl.org>
Wed, 7 Aug 2019 09:46:26 +0000 (10:46 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 8 Aug 2019 09:11:16 +0000 (10:11 +0100)
We move an OPENSSL_init_crypto call slightly earlier in the process to
avoid calling it while holding the store lock. This can lead to deadlocks.

Fixes the no-engine build.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9547)

crypto/provider_core.c

index 76d526eaf0ba1d92049f82c3968f092dcafe9bb0..a821d17e46afedc8505dcb7147a4f342a2dee306 100644 (file)
@@ -566,14 +566,6 @@ static int provider_forall_loaded(struct provider_store_st *store,
     int ret = 1;
     int num_provs;
 
-#ifndef FIPS_MODE
-    /*
-     * Make sure any providers are loaded from config before we try to use
-     * them.
-     */
-    OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
-#endif
-
     num_provs = sk_OSSL_PROVIDER_num(store->providers);
 
     if (found_activated != NULL)
@@ -638,6 +630,14 @@ int ossl_provider_forall_loaded(OPENSSL_CTX *ctx,
     int ret = 1;
     struct provider_store_st *store = get_provider_store(ctx);
 
+#ifndef FIPS_MODE
+    /*
+     * Make sure any providers are loaded from config before we try to use
+     * them.
+     */
+    OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, NULL);
+#endif
+
     if (store != NULL) {
         CRYPTO_THREAD_read_lock(store->lock);