Skip to contentSkip to conversation

Don't manually free DH params in OpenSSL 3

PATCH In review Max Fillinger 3 participants 3 messages Oct 25, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Don't manually free DH params in OpenSSL 3

When the EVP_PKEY object with the Diffie-Hellman parameters is passed to SSL_CTX_set0_tmp_dh_pkey, it does not create a copy but stores the pointer in the SSL_CTX. Therefore, we should not free it.

The EVP_PKEY will be freed automatically when we free the SSL_CTX.

---
 src/openvpn/ssl_openssl.c | 2 --
 1 file changed, 2 deletions(-)
src/openvpn/ssl_openssl.c +0 -2
index 2414fc5e..6f2d6d57 100644
@@ -685,8 +685,6 @@ tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file,
 
     msg(D_TLS_DEBUG_LOW, "Diffie-Hellman initialized with %d bit key",
         8 * EVP_PKEY_get_size(dh));
-
-    EVP_PKEY_free(dh);
 #else
     DH *dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
     BIO_free(bio);
Signature · 1 line
2.11.0
Acked-by on v1 1/1
#1 lore raw

Am 25.10.21 um 16:53 schrieb Max Fillinger:

Quoted 6 lines

When the EVP_PKEY object with the Diffie-Hellman parameters is passed to SSL_CTX_set0_tmp_dh_pkey, it does not create a copy but stores the pointer in the SSL_CTX. Therefore, we should not free it.

The EVP_PKEY will be freed automatically when we free the SSL_CTX.

Yes. The set0 indicates that it does a direct reference.

#2 lore raw
In reply to Max Fillinger

Great find.

I had this trac ticket (1436) about weird hanging/looping on signal exit, inside openssl cleanup, and your patch fixes this :-)

Your patch has been applied to the master branch.

commit 4daed27f28f6bb3033e659328fe80322a8f4b5e1

Author: Max Fillinger
Date:   Mon Oct 25 16:53:14 2021 +0200
     Don't manually free DH params in OpenSSL 3

     Signed-off-by: Max Fillinger <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/search?l=mid&[email protected]...
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering