Commit f3e3dd00b0 for openssl.org

commit f3e3dd00b01856659d57d15991b4994419c63893
Author: Sabith Saheb <shabi7204192361@gmail.com>
Date:   Fri Oct 23 17:42:48 2026 +0530

    ecx_kmgmt: free the private key with the secure heap aware free

    ecx_set_params() discards the private key when a new encoded public
    key is set through OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, which is what
    EVP_PKEY_set1_encoded_public_key() uses for provided keys. It released
    the key with OPENSSL_clear_free(), but ossl_ecx_key_allocate_privkey()
    allocates the private key of generated and derived ECX keys with
    OPENSSL_secure_zalloc(). When the application has enabled the secure
    heap with CRYPTO_secure_malloc_init(), the pointer lives in the locked
    arena and OPENSSL_clear_free() hands it to the system free(). ASan
    reports a bad-free in ecx_set_params and the arena allocation is never
    returned, so CRYPTO_secure_malloc_done() can no longer release the heap.

    Use OPENSSL_secure_clear_free() like every other release of an ECX
    private key (ossl_ecx_key_free, ossl_ecx_key_fromdata). It falls back to
    the normal free for keys that were imported with OPENSSL_malloc().

    Fixes: 6a9bd9298bd7 "Make EVP_PKEY_[get1|set1]_tls_encodedpoint work with provided keys"
    Assisted-by: Claude Code:claude-fable-5-1
    Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
    Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
    Merge-date: Fri Oct 30 03:45:12 2026
    Merged-from: https://github.com/openssl/openssl/pull/33360

diff --git a/providers/implementations/keymgmt/ecx_kmgmt.c b/providers/implementations/keymgmt/ecx_kmgmt.c
index a12b02e41a..eb075ef568 100644
--- a/providers/implementations/keymgmt/ecx_kmgmt.c
+++ b/providers/implementations/keymgmt/ecx_kmgmt.c
@@ -449,7 +449,7 @@ static int ecx_set_params(void *key, const OSSL_PARAM params[])
             || !OSSL_PARAM_get_octet_string(p.pub, &buf, sizeof(ecxkey->pubkey),
                 NULL))
             return 0;
-        OPENSSL_clear_free(ecxkey->privkey, ecxkey->keylen);
+        OPENSSL_secure_clear_free(ecxkey->privkey, ecxkey->keylen);
         ecxkey->privkey = NULL;
         ecxkey->haspubkey = 1;
     }