Browse Source

Fix a failure where fetches can return NULL in multi-threaded code

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)
master
Matt Caswell 1 year ago
parent
commit
b11ba50fd9
1 changed files with 10 additions and 0 deletions
  1. +10
    -0
      crypto/core_fetch.c

+ 10
- 0
crypto/core_fetch.c View 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);
}


Loading…
Cancel
Save