Skip to contentSkip to conversation

Fix a potential memory leak in tls_ctx_use_management_external_key

PATCH In review [email protected]... 3 participants 3 messages Jan 20, 2022 – Jan 26, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix a potential memory leak in tls_ctx_use_management_external_key

From: Selva Nair <[email protected]...>

As pointed out by Gert Doering <[email protected]...>

---
To be applied after 06/18 of xkey patchset

 src/openvpn/ssl_openssl.c | 1 +
 1 file changed, 1 insertion(+)
src/openvpn/ssl_openssl.c +1 -0
index b48845eb..3f8c3091 100644
@@ -1493,6 +1493,7 @@ tls_ctx_use_management_external_key(struct tls_root_ctx *ctx)
     if (!privkey
         || !SSL_CTX_use_PrivateKey(ctx->ctx, privkey))
     {
+        EVP_PKEY_free(privkey);
         goto cleanup;
     }
     EVP_PKEY_free(privkey);
Signature · 1 line
2.30.2
Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 3 lines · On 20/01/2022 17:26, [email protected]... wrote:

From: Selva Nair <[email protected]...>

As pointed out by Gert Doering <[email protected]...>

This can be "gitified" as:

Quoted 13 lines

---
To be applied after 06/18 of xkey patchset

  src/openvpn/ssl_openssl.c | 1 +
  1 file changed, 1 insertion(+)
src/openvpn/ssl_openssl.c +0 -0
index b48845eb..3f8c3091 100644

src/openvpn/ssl_openssl.c tls_ctx_use_management_external_key(struct tls_root_ctx *ctx) · line 1499

Quoted 7 lines
src/openvpn/ssl_openssl.c +1 -0
@@ -1493,6 +1493,7 @@ tls_ctx_use_management_external_key(struct tls_root_ctx *ctx)
      if (!privkey
          || !SSL_CTX_use_PrivateKey(ctx->ctx, privkey))
      {
+        EVP_PKEY_free(privkey);
          goto cleanup;
      }
      EVP_PKEY_free(privkey);

This is non-crucial because we goto cleanup and then do a M_FATAL.

Nonetheless, we should strive to have cleaner error paths that take care of releasing allocated resources when possible.

Signature · 1 line
Antonio Quartulli
#2 lore raw
In reply to [email protected]...

Thanks.

Even if, as Antonio noticed, we will only leak memory for a very short time before hitting the M_FATAL message in "cleanup"...

Your patch has been applied to the master branch.

commit 0f7cd474118deeced48168ed9cec0806e7f4cc15

Author: Selva Nair
Date:   Thu Jan 20 11:26:45 2022 -0500
     Fix a potential memory leak in tls_ctx_use_management_external_key

     Signed-off-by: Selva Nair <[email protected]...>
     Acked-by: Antonio Quartulli <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg23610.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering