summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/crypto_ex_data.c
diff options
context:
space:
mode:
authorkenjiro <>2026-08-30 12:19:37 +0000
committerkenjiro <>2026-08-30 12:19:37 +0000
commit5931045c664b500427fb54c31fab4de3e92bb159 (patch)
tree6bcb237ddd3233dde465de629eee51c4c1a0ed2c /src/lib/libcrypto/crypto_ex_data.c
parent6b13eef79d2dc54c1b0203f967b3fc8b8971df78 (diff)
downloadopenbsd-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.c15
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
24struct crypto_ex_data { 26struct crypto_ex_data {
@@ -151,6 +153,16 @@ LCRYPTO_ALIAS(CRYPTO_get_ex_new_index);
151void 153void
152CRYPTO_cleanup_all_ex_data(void) 154CRYPTO_cleanup_all_ex_data(void)
153{ 155{
156}
157LCRYPTO_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 */
163void
164crypto_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}
176LCRYPTO_ALIAS(CRYPTO_cleanup_all_ex_data);
177 188
178static void 189static void
179crypto_ex_data_clear(CRYPTO_EX_DATA *exdata) 190crypto_ex_data_clear(CRYPTO_EX_DATA *exdata)