Use OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL) in libcrypto
authorTomas Mraz <tomas@openssl.org>
Thu, 11 Mar 2021 17:02:52 +0000 (18:02 +0100)
committerTomas Mraz <tomas@openssl.org>
Fri, 12 Mar 2021 14:11:21 +0000 (15:11 +0100)
Calling OPENSSL_init_crypto(0, NULL) is a no-op and will
not properly initialize thread local handling.

Only the calls that are needed to initialize thread locals
are kept, the rest of the no-op calls are removed.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14497)

crypto/bio/b_addr.c
crypto/engine/eng_lib.c
crypto/err/err.c
crypto/rand/rand_lib.c
crypto/store/store_init.c
crypto/store/store_local.h
crypto/store/store_register.c

index 841cc58100474812fb8e590213862b87b232208a..635f84e1830840150e9a484210506d456a40d7fe 100644 (file)
@@ -616,8 +616,6 @@ static int addrinfo_wrap(int family, int socktype,
 
 DEFINE_RUN_ONCE_STATIC(do_bio_lookup_init)
 {
-    if (!OPENSSL_init_crypto(0, NULL))
-        return 0;
     bio_lookup_lock = CRYPTO_THREAD_lock_new();
     return bio_lookup_lock != NULL;
 }
index 72e463a899ae613f04347426a876c62bfdbca8e6..4a01104462e0a8b414b79eba820143a71a0bd9ac 100644 (file)
@@ -20,8 +20,6 @@ CRYPTO_ONCE engine_lock_init = CRYPTO_ONCE_STATIC_INIT;
 
 DEFINE_RUN_ONCE(do_engine_lock_init)
 {
-    if (!OPENSSL_init_crypto(0, NULL))
-        return 0;
     global_engine_lock = CRYPTO_THREAD_lock_new();
     return global_engine_lock != NULL;
 }
index e5f98668131aff3c00d6c796c0c8f42509d48762..a8bde92674e22366c34884f28f956a6e64d3887e 100644 (file)
@@ -197,7 +197,7 @@ static void ERR_STATE_free(ERR_STATE *s)
 
 DEFINE_RUN_ONCE_STATIC(do_err_strings_init)
 {
-    if (!OPENSSL_init_crypto(0, NULL))
+    if (!OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL))
         return 0;
     err_string_lock = CRYPTO_THREAD_lock_new();
     if (err_string_lock == NULL)
index 0ee57dc4600f74b7094d04bbc3b754c9a18d5ac6..e248d5753a0718559ef6fa2ac7572918a9a344d8 100644 (file)
@@ -429,7 +429,7 @@ static void *rand_ossl_ctx_new(OSSL_LIB_CTX *libctx)
      * We need to ensure that base libcrypto thread handling has been
      * initialised.
      */
-     OPENSSL_init_crypto(0, NULL);
+     OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL);
 #endif
 
     dgbl->lock = CRYPTO_THREAD_lock_new();
index d308dc5d0b36a12e3f818caae93aae56f3449ad9..dc507c67510b506994ec1a1ebc08f6b9d6801169 100644 (file)
@@ -7,25 +7,9 @@
  * https://www.openssl.org/source/license.html
  */
 
-#include <openssl/err.h>
 #include "crypto/store.h"
 #include "store_local.h"
 
-static CRYPTO_ONCE store_init = CRYPTO_ONCE_STATIC_INIT;
-DEFINE_RUN_ONCE_STATIC(do_store_init)
-{
-    return OPENSSL_init_crypto(0, NULL);
-}
-
-int ossl_store_init_once(void)
-{
-    if (!RUN_ONCE(&store_init, do_store_init)) {
-        ERR_raise(ERR_LIB_OSSL_STORE, ERR_R_MALLOC_FAILURE);
-        return 0;
-    }
-    return 1;
-}
-
 void ossl_store_cleanup_int(void)
 {
     ossl_store_destroy_loaders_int();
index 56a90a125b8471bb06670bd32735d3b77664333c..16989707d6ec74e2cc42bc624d4795b919d7cbb4 100644 (file)
@@ -152,13 +152,6 @@ struct ossl_store_ctx_st {
     struct ossl_passphrase_data_st pwdata;
 };
 
-/*-
- *  OSSL_STORE init stuff
- *  ---------------------
- */
-
-int ossl_store_init_once(void);
-
 /*-
  *  'file' scheme stuff
  *  -------------------
index f426a82ecc6952b836a4fce950c3ed065bfcc2a8..51bd5917906d46a5c0bdf2b41546ddee272322db 100644 (file)
@@ -207,8 +207,6 @@ int ossl_store_register_loader_int(OSSL_STORE_LOADER *loader)
 }
 int OSSL_STORE_register_loader(OSSL_STORE_LOADER *loader)
 {
-    if (!ossl_store_init_once())
-        return 0;
     return ossl_store_register_loader_int(loader);
 }
 
@@ -224,9 +222,6 @@ const OSSL_STORE_LOADER *ossl_store_get0_loader_int(const char *scheme)
     template.close = NULL;
     template.open_ex = NULL;
 
-    if (!ossl_store_init_once())
-        return NULL;
-
     if (!RUN_ONCE(&registry_init, do_registry_init)) {
         ERR_raise(ERR_LIB_OSSL_STORE, ERR_R_MALLOC_FAILURE);
         return NULL;
@@ -275,8 +270,6 @@ OSSL_STORE_LOADER *ossl_store_unregister_loader_int(const char *scheme)
 }
 OSSL_STORE_LOADER *OSSL_STORE_unregister_loader(const char *scheme)
 {
-    if (!ossl_store_init_once())
-        return 0;
     return ossl_store_unregister_loader_int(scheme);
 }