Commit 73f3bd8871 for openssl.org
commit 73f3bd88714957382a0a9e6e9e761ddb76db82a4
Author: Richard Levitte <levitte@openssl.foundation>
Date: Thu Aug 27 10:22:12 2026 +0200
Fix potential double-free in dsa_finish()
dsa_finish() (the default DSA method's finish slot) frees the cached
Montgomery context, dsa->method_mont_p, without NULLing the pointer.
Once the cache has been warmed (e.g. by signing), a subsequent
finish call — e.g. via DSA_free() after DSA_set_method() — frees it
again.
NULL the pointer after freeing.
Fixes: https://github.com/openssl/openssl/issues/32541
Assisted-by: Pi:moonshotai/kimi-k3
Signed-off-by: Richard Levitte <levitte@openssl.foundation>
Reviewed-by: Jakub Zelenka <jakub.zelenka@openssl.foundation>
Reviewed-by: Matt Caswell <matt@openssl.foundation>
Merge-date: Sun Aug 30 14:54:56 2026
Merged-from: https://github.com/openssl/openssl/pull/32543
diff --git a/crypto/dsa/dsa_ossl.c b/crypto/dsa/dsa_ossl.c
index b6706cd52a..142140c63a 100644
--- a/crypto/dsa/dsa_ossl.c
+++ b/crypto/dsa/dsa_ossl.c
@@ -468,6 +468,7 @@ static int dsa_init(DSA *dsa)
static int dsa_finish(DSA *dsa)
{
BN_MONT_CTX_free(dsa->method_mont_p);
+ dsa->method_mont_p = NULL;
return 1;
}