Skip to content

Commit 12c98cd

Browse files
authored
Initialize locking sooner (#3456)
1 parent fdd35b9 commit 12c98cd

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

utils/s2n_init.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@ int s2n_disable_atexit(void) {
4949
int s2n_init(void)
5050
{
5151
main_thread = pthread_self();
52+
/* Should run before any init method that calls libcrypto methods
53+
* to ensure we don't try to call methods that don't exist.
54+
* It doesn't require any locks since it only deals with values that
55+
* should be constant, so can run before s2n_locking_init. */
5256
POSIX_GUARD_RESULT(s2n_libcrypto_validate_runtime());
53-
POSIX_GUARD(s2n_fips_init());
57+
/* Must run before any init method that allocates memory. */
5458
POSIX_GUARD(s2n_mem_init());
55-
POSIX_GUARD_RESULT(s2n_rand_init());
59+
/* Must run before any init method that calls libcrypto methods. */
5660
POSIX_GUARD_RESULT(s2n_locking_init());
61+
POSIX_GUARD(s2n_fips_init());
62+
POSIX_GUARD_RESULT(s2n_rand_init());
5763
POSIX_GUARD(s2n_cipher_suites_init());
5864
POSIX_GUARD(s2n_security_policies_init());
5965
POSIX_GUARD(s2n_config_defaults_init());
@@ -82,9 +88,9 @@ static bool s2n_cleanup_atexit_impl(void)
8288
/* the configs need to be wiped before resetting the memory callbacks */
8389
s2n_wipe_static_configs();
8490

85-
return s2n_result_is_ok(s2n_locking_cleanup()) &&
86-
s2n_result_is_ok(s2n_rand_cleanup_thread()) &&
91+
return s2n_result_is_ok(s2n_rand_cleanup_thread()) &&
8792
s2n_result_is_ok(s2n_rand_cleanup()) &&
93+
s2n_result_is_ok(s2n_locking_cleanup()) &&
8894
(s2n_mem_cleanup() == S2N_SUCCESS);
8995
}
9096

0 commit comments

Comments
 (0)