]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix a failure where fetches can return NULL in multi-threaded code
authorMatt Caswell <matt@openssl.org>
Tue, 12 Jan 2021 16:50:17 +0000 (16:50 +0000)
committerMatt Caswell <matt@openssl.org>
Thu, 14 Jan 2021 17:30:46 +0000 (17:30 +0000)
When a fetch is attempted simultaneously from multiple threads then both
threads can attempt to construct the method. However only one of those
will get added to the global evp method store. The one that "lost" the
race to add the method to the global evp method store ended up with the
fetch call returning NULL, instead of returning the method that was
already available.

Fixes #13682

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13660)

crypto/core_fetch.c

index 4fb432754b377189a1f45d6c90fcdcfc19df246d..12d52a03d049d291fd1998d50402493b23e89563 100644 (file)
@@ -128,6 +128,16 @@ void *ossl_method_construct(OSSL_LIB_CTX *libctx, int operation_id,
                               &cbdata);
 
         method = mcm->get(libctx, cbdata.store, mcm_data);
+        if (method == NULL) {
+            /*
+             * If we get here then we did not construct the method that we
+             * attempted to construct. It's possible that another thread got
+             * there first and so we skipped construction (pre-condition
+             * failed). We check the global store again to see if it has
+             * appeared by now.
+             */
+            method = mcm->get(libctx, NULL, mcm_data);
+        }
         mcm->dealloc_tmp_store(cbdata.store);
     }