diff options
author | jsing <> | 2025-05-24 07:41:14 +0000 |
---|---|---|
committer | jsing <> | 2025-05-24 07:41:14 +0000 |
commit | d75f6fd37c90033bcb088aa5518ce6263f10d56b (patch) | |
tree | 12cd3854c24e4610127fc8cdbb4d5270c910a795 /src/lib/libcrypto | |
parent | 19481faae98e76fb30ab33568501e385e3bcd1a3 (diff) | |
download | openbsd-d75f6fd37c90033bcb088aa5518ce6263f10d56b.tar.gz openbsd-d75f6fd37c90033bcb088aa5518ce6263f10d56b.tar.bz2 openbsd-d75f6fd37c90033bcb088aa5518ce6263f10d56b.zip |
Provide openssl_init_crypto_constructor() and invoke via a constructor.
There are a very large number of entry points to libcrypto, which means it
is easy to run code prior to OPENSSL_init_crypto() being invoked. This
means that CPU capability detection will not have been run, leading to
poor choices with regards to the use of accelerated implementations.
Now that our CPU capability detection code has been cleaned up and is safe,
provide an openssl_init_crypto_constructor() that runs CPU capability
detection and invoke it as a library constructor. This should only be used
to invoke code that does not do memory allocation or trigger signals.
ok tb@
Diffstat (limited to 'src/lib/libcrypto')
-rw-r--r-- | src/lib/libcrypto/crypto_init.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/lib/libcrypto/crypto_init.c b/src/lib/libcrypto/crypto_init.c index 44c4846762..79c100f668 100644 --- a/src/lib/libcrypto/crypto_init.c +++ b/src/lib/libcrypto/crypto_init.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: crypto_init.c,v 1.24 2025/05/24 07:23:14 jsing Exp $ */ | 1 | /* $OpenBSD: crypto_init.c,v 1.25 2025/05/24 07:41:14 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2018 Bob Beck <beck@openbsd.org> |
4 | * | 4 | * |
@@ -37,6 +37,8 @@ static pthread_once_t crypto_init_once = PTHREAD_ONCE_INIT; | |||
37 | static pthread_t crypto_init_thread; | 37 | static pthread_t crypto_init_thread; |
38 | static int crypto_init_cleaned_up; | 38 | static int crypto_init_cleaned_up; |
39 | 39 | ||
40 | void openssl_init_crypto_constructor(void) __attribute__((constructor)); | ||
41 | |||
40 | #ifndef HAVE_CRYPTO_CPU_CAPS_INIT | 42 | #ifndef HAVE_CRYPTO_CPU_CAPS_INIT |
41 | void | 43 | void |
42 | crypto_cpu_caps_init(void) | 44 | crypto_cpu_caps_init(void) |
@@ -44,6 +46,17 @@ crypto_cpu_caps_init(void) | |||
44 | } | 46 | } |
45 | #endif | 47 | #endif |
46 | 48 | ||
49 | /* | ||
50 | * This function is invoked as a constructor when the library is loaded. The | ||
51 | * code run from here must not allocate memory or trigger signals. The only | ||
52 | * safe code is to read data and update global variables. | ||
53 | */ | ||
54 | void | ||
55 | openssl_init_crypto_constructor(void) | ||
56 | { | ||
57 | crypto_cpu_caps_init(); | ||
58 | } | ||
59 | |||
47 | void | 60 | void |
48 | OPENSSL_init(void) | 61 | OPENSSL_init(void) |
49 | { | 62 | { |
@@ -55,8 +68,6 @@ OPENSSL_init_crypto_internal(void) | |||
55 | { | 68 | { |
56 | crypto_init_thread = pthread_self(); | 69 | crypto_init_thread = pthread_self(); |
57 | 70 | ||
58 | crypto_cpu_caps_init(); | ||
59 | |||
60 | ERR_load_crypto_strings(); | 71 | ERR_load_crypto_strings(); |
61 | } | 72 | } |
62 | 73 | ||