]> git.ipfire.org Git - thirdparty/openssl.git/commit
Fix usage of deallocated EVP_RAND_CTX after execution of FIPS on-demand self tests
authorKarol Brzuskiewicz <kabr@arista.com>
Mon, 10 Jun 2024 08:48:31 +0000 (01:48 -0700)
committerTomas Mraz <tomas@openssl.org>
Mon, 24 Jun 2024 17:02:43 +0000 (19:02 +0200)
commit42a8ef844e5fca55abb608beb62695abe80c6b6d
treebe9dd7d72cea36de3b101eb4c0ccdd756ac53c90
parentd38f62ea118170fc40e10f6f95b180cccbaa7581
Fix usage of deallocated EVP_RAND_CTX after execution of FIPS on-demand self tests

Once RNG is used, triggering FIPS on-demand self tests (via
OSSL_PROVIDER_self_test() API) crashes the application. This happens because the
RNG context is stored before self tests, and restored after their execution.
In the meantime - before context restoration - RAND_set0_private() function is
called, which decrements the stored RNG context reference counter and frees it.
To resolve the issue, the stored RNG context refcount has been incremented via
the EVP_RAND_CTX_up_ref() API to avoid its deallocation during the RNG context
switch performed by the self test function.
The provider_status_test test has been updated to reproduce the issue as
a regression test.

Signed-off-by: Karol Brzuskiewicz <kabr@arista.com>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24599)
providers/fips/self_test_kats.c
test/provider_status_test.c