From 7cae4263860648f49417f2d5a8a3728329ab109a Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Thu, 30 Nov 2023 11:20:34 -0500 Subject: [PATCH] Statically link legacy provider to evp_extra_test Like in #17345, evp_extra_test links libcrypto statically, but also has a dynamic/shared load via the legacy provider, which leads to ambiguous behavior in evp_extra_test on some platforms, usually a crash (SIGSEGV) on exit via the atexit handlers. Statically link the legacy provider to avoid this. Fixes #22819 Helped-by: Neil Horman Helped-by: Tomas Mraz Signed-off-by: Randall S. Becker Reviewed-by: Tom Cosgrove Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/22904) (cherry picked from commit 426d34fc1302eb0d2f5a6152621c105ea2d198b6) --- test/build.info | 8 ++++++++ test/evp_extra_test.c | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/test/build.info b/test/build.info index 9bed40eeb1d..82740dcb6e4 100644 --- a/test/build.info +++ b/test/build.info @@ -172,6 +172,14 @@ IF[{- !$disabled{tests} -}] SOURCE[evp_extra_test]=evp_extra_test.c INCLUDE[evp_extra_test]=../include ../apps/include DEPEND[evp_extra_test]=../libcrypto.a libtestutil.a + IF[{- !$disabled{module} && !$disabled{legacy} -}] + DEFINE[evp_extra_test]=STATIC_LEGACY + SOURCE[evp_extra_test]=../providers/legacyprov.c + INCLUDE[evp_extra_test]=../providers/common/include \ + ../providers/implementations/include + DEPEND[evp_extra_test]=../providers/liblegacy.a \ + ../providers/libcommon.a + ENDIF SOURCE[evp_extra_test2]=evp_extra_test2.c INCLUDE[evp_extra_test2]=../include ../apps/include diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index e8700ca8d11..72892261bd2 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -37,6 +37,10 @@ #include "internal/sizes.h" #include "crypto/evp.h" +#ifdef STATIC_LEGACY +OSSL_provider_init_fn ossl_legacy_provider_init; +#endif + static OSSL_LIB_CTX *testctx = NULL; static char *testpropq = NULL; @@ -5237,6 +5241,15 @@ int setup_tests(void) testctx = OSSL_LIB_CTX_new(); if (!TEST_ptr(testctx)) return 0; +#ifdef STATIC_LEGACY + /* + * This test is always statically linked against libcrypto. We must not + * attempt to load legacy.so that might be dynamically linked against + * libcrypto. Instead we use a built-in version of the legacy provider. + */ + if (!OSSL_PROVIDER_add_builtin(testctx, "legacy", ossl_legacy_provider_init)) + return 0; +#endif /* Swap the libctx to test non-default context only */ nullprov = OSSL_PROVIDER_load(NULL, "null"); deflprov = OSSL_PROVIDER_load(testctx, "default"); -- 2.47.2