diff options
author | Rich Salz <rsalz@akamai.com> | 2021-02-18 15:31:56 -0500 |
---|---|---|
committer | Pauli <ppzgs1@gmail.com> | 2021-03-14 15:33:34 +1000 |
commit | cd3f8c1b11b0b9f4163bc8c62cbae38aec1b4030 (patch) | |
tree | de59d50b2ff9b2bd73a1ebf08eedf78d8ba44aa3 /providers | |
parent | f62846b703d163265176fe960ec7d087b4c3fa96 (diff) |
Always check CRYPTO_LOCK_{read,write}_lock
Some functions that lock things are void, so we just return early.
Also make ossl_namemap_empty return 0 on error. Updated the docs, and added
some code to ossl_namemap_stored() to handle the failure, and updated the
tests to allow for failure.
Fixes: #14230
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14238)
Diffstat (limited to 'providers')
-rw-r--r-- | providers/fips/self_test.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/providers/fips/self_test.c b/providers/fips/self_test.c index b20af1bd6c..dbd744ff7c 100644 --- a/providers/fips/self_test.c +++ b/providers/fips/self_test.c @@ -11,6 +11,7 @@ #include <openssl/evp.h> #include <openssl/params.h> #include <openssl/crypto.h> +#include <internal/cryptlib.h> #include <openssl/fipskey.h> #include <openssl/err.h> #include <openssl/proverr.h> @@ -212,9 +213,10 @@ err: static void set_fips_state(int state) { - CRYPTO_THREAD_write_lock(fips_state_lock); - FIPS_state = state; - CRYPTO_THREAD_unlock(fips_state_lock); + if (ossl_assert(CRYPTO_THREAD_write_lock(fips_state_lock) != 0)) { + FIPS_state = state; + CRYPTO_THREAD_unlock(fips_state_lock); + } } /* This API is triggered either on loading of the FIPS module or on demand */ @@ -232,7 +234,8 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS *st, int on_demand_test) if (!RUN_ONCE(&fips_self_test_init, do_fips_self_test_init)) return 0; - CRYPTO_THREAD_read_lock(fips_state_lock); + if (!CRYPTO_THREAD_read_lock(fips_state_lock)) + return 0; loclstate = FIPS_state; CRYPTO_THREAD_unlock(fips_state_lock); @@ -244,8 +247,12 @@ int SELF_TEST_post(SELF_TEST_POST_PARAMS *st, int on_demand_test) return 0; } - CRYPTO_THREAD_write_lock(self_test_lock); - CRYPTO_THREAD_read_lock(fips_state_lock); + if (!CRYPTO_THREAD_write_lock(self_test_lock)) + return 0; + if (!CRYPTO_THREAD_read_lock(fips_state_lock)) { + CRYPTO_THREAD_unlock(self_test_lock); + return 0; + } if (FIPS_state == FIPS_STATE_RUNNING) { CRYPTO_THREAD_unlock(fips_state_lock); if (!on_demand_test) { |