From 2966a4a33c3f734717d35e9f472edff7883efaba Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 3 Dec 2024 13:40:32 +0100 Subject: [PATCH] tests: Call disable_secmem() before ssh_init() ssh_init calls ssh_crypto_init() which initializes the secure memory of gcrypt. Those should actually be just called by the application once. Lets do that. Signed-off-by: Andreas Schneider Reviewed-by: Jakub Jelen --- tests/unittests/torture_threads_pki_rsa.c | 27 +++++------------------ 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/tests/unittests/torture_threads_pki_rsa.c b/tests/unittests/torture_threads_pki_rsa.c index b7c5630f..64d9d504 100644 --- a/tests/unittests/torture_threads_pki_rsa.c +++ b/tests/unittests/torture_threads_pki_rsa.c @@ -133,10 +133,9 @@ static int teardown(void **state) { return 0; } -static int disable_secmem(void **state) +static void +disable_secmem(void) { - (void) state; /*unused*/ - #if defined(HAVE_LIBGCRYPT) /* gcrypt currently is configured to use only 4kB of locked secmem * (see ssh_crypto_init() in src/libcrypt.c) @@ -145,23 +144,10 @@ static int disable_secmem(void **state) * To avoid the expected warning, disable the secure memory. * */ - gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); + gcry_control(GCRYCTL_SUSPEND_SECMEM_WARN); gcry_control(GCRYCTL_DISABLE_SECMEM); + gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); #endif - - return 0; -} - -static int enable_secmem(void **state) -{ - (void) state; /*unused*/ - -#if defined(HAVE_LIBGCRYPT) - /* Re-enable secmem */ - gcry_control(GCRYCTL_INIT_SECMEM, 4096); - gcry_control(GCRYCTL_RESUME_SECMEM_WARN); -#endif - return 0; } static void *thread_pki_rsa_import_pubkey_file(void *threadid) @@ -784,9 +770,7 @@ int torture_run_tests(void) cmocka_unit_test_setup_teardown(torture_pki_rsa_duplicate_key, setup_rsa_key, teardown), - cmocka_unit_test_setup_teardown(torture_pki_rsa_generate_key, - disable_secmem, - enable_secmem), + cmocka_unit_test(torture_pki_rsa_generate_key), cmocka_unit_test_setup_teardown(torture_mixed, setup_rsa_key, teardown), }; @@ -802,6 +786,7 @@ int torture_run_tests(void) * If the library is statically linked, ssh_init() is not called * automatically */ + disable_secmem(); ssh_init(); torture_filter_tests(tests); rc = cmocka_run_group_tests(tests, NULL, NULL);