]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Fix use-after-free with EVP_CIPHER_free
authorArne Schwabe <arne@rfc2549.org>
Thu, 1 Jun 2023 09:57:21 +0000 (11:57 +0200)
committerGert Doering <gert@greenie.muc.de>
Sat, 3 Jun 2023 08:02:22 +0000 (10:02 +0200)
In many scenarios the context will still have a reference to the cipher, so
this use-after-free does not explode but it is still wrong.

Change-Id: I59002d6613eaef36d5a47b20b56073e399cfa1df
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Antonio Quartulli <a@unstable.cc>
Message-Id: <20230601095721.4065834-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26735.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/crypto_openssl.c

index c2ac80b741eeff98af3def849b61faaa15470b39..f5372f85ab26c5b5f9c1f1f4df26ae9625a9e0f0 100644 (file)
@@ -839,9 +839,9 @@ cipher_ctx_init(EVP_CIPHER_CTX *ctx, const uint8_t *key,
         crypto_msg(M_FATAL, "EVP cipher init #2");
     }
 
-    EVP_CIPHER_free(kt);
     /* make sure we used a big enough key */
     ASSERT(EVP_CIPHER_CTX_key_length(ctx) <= EVP_CIPHER_key_length(kt));
+    EVP_CIPHER_free(kt);
 }
 
 int