diff options
| author | kenjiro <> | 2026-08-30 12:19:37 +0000 |
|---|---|---|
| committer | kenjiro <> | 2026-08-30 12:19:37 +0000 |
| commit | 5931045c664b500427fb54c31fab4de3e92bb159 (patch) | |
| tree | 6bcb237ddd3233dde465de629eee51c4c1a0ed2c /src/lib/libcrypto/crypto_ex_data.c | |
| parent | 6b13eef79d2dc54c1b0203f967b3fc8b8971df78 (diff) | |
| download | openbsd-5931045c664b500427fb54c31fab4de3e92bb159.tar.gz openbsd-5931045c664b500427fb54c31fab4de3e92bb159.tar.bz2 openbsd-5931045c664b500427fb54c31fab4de3e92bb159.zip | |
Make CRYPTO_cleanup_all_ex_data() a compatibility no-op
The ex_data callback registry is process-wide, but this API could free
it while other threads were still using libcrypto, resulting in a
use-after-free.
Retain the public symbol as a compatibility no-op and mark it
deprecated. Move the actual cleanup to an internal function called by
OPENSSL_cleanup(). Replace the in-tree callers with OPENSSL_cleanup()
at final shutdown to preserve cleanup behavior and coverage.
Document both APIs and the requirement that OPENSSL_cleanup() only be
called after all threads and components have stopped using libcrypto.
ok tb
Diffstat (limited to 'src/lib/libcrypto/crypto_ex_data.c')
| -rw-r--r-- | src/lib/libcrypto/crypto_ex_data.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/lib/libcrypto/crypto_ex_data.c b/src/lib/libcrypto/crypto_ex_data.c index 233905f888..2066098653 100644 --- a/src/lib/libcrypto/crypto_ex_data.c +++ b/src/lib/libcrypto/crypto_ex_data.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: crypto_ex_data.c,v 1.6 2025/06/15 15:58:56 tb Exp $ */ | 1 | /* $OpenBSD: crypto_ex_data.c,v 1.7 2026/08/30 12:19:37 kenjiro Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -19,6 +19,8 @@ | |||
| 19 | 19 | ||
| 20 | #include <openssl/crypto.h> | 20 | #include <openssl/crypto.h> |
| 21 | 21 | ||
| 22 | #include "crypto_internal.h" | ||
| 23 | |||
| 22 | #define CRYPTO_EX_DATA_MAX_INDEX 32 | 24 | #define CRYPTO_EX_DATA_MAX_INDEX 32 |
| 23 | 25 | ||
| 24 | struct crypto_ex_data { | 26 | struct crypto_ex_data { |
| @@ -151,6 +153,16 @@ LCRYPTO_ALIAS(CRYPTO_get_ex_new_index); | |||
| 151 | void | 153 | void |
| 152 | CRYPTO_cleanup_all_ex_data(void) | 154 | CRYPTO_cleanup_all_ex_data(void) |
| 153 | { | 155 | { |
| 156 | } | ||
| 157 | LCRYPTO_ALIAS(CRYPTO_cleanup_all_ex_data); | ||
| 158 | |||
| 159 | /* | ||
| 160 | * Free process-wide ex_data state during OPENSSL_cleanup(). The caller must | ||
| 161 | * ensure that no other thread is using libcrypto. | ||
| 162 | */ | ||
| 163 | void | ||
| 164 | crypto_ex_data_cleanup(void) | ||
| 165 | { | ||
| 154 | struct crypto_ex_data_class *class; | 166 | struct crypto_ex_data_class *class; |
| 155 | int i, j; | 167 | int i, j; |
| 156 | 168 | ||
| @@ -173,7 +185,6 @@ CRYPTO_cleanup_all_ex_data(void) | |||
| 173 | free(classes); | 185 | free(classes); |
| 174 | classes = NULL; | 186 | classes = NULL; |
| 175 | } | 187 | } |
| 176 | LCRYPTO_ALIAS(CRYPTO_cleanup_all_ex_data); | ||
| 177 | 188 | ||
| 178 | static void | 189 | static void |
| 179 | crypto_ex_data_clear(CRYPTO_EX_DATA *exdata) | 190 | crypto_ex_data_clear(CRYPTO_EX_DATA *exdata) |
