]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Avoid potential double-free with duplicated hybrid ML-KEM keys
authorViktor Dukhovni <openssl-users@dukhovni.org>
Thu, 27 Mar 2025 01:34:50 +0000 (12:34 +1100)
committerTomas Mraz <tomas@openssl.org>
Fri, 28 Mar 2025 13:10:48 +0000 (14:10 +0100)
Issue reported by Apple Inc on 2025-03-26.

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27173)

providers/implementations/keymgmt/mlx_kmgmt.c

index b8c3dd45c2724a66a52286c37649ee6a7d6c9b82..bea8783276093b0efcbd4108f47867fc4166e184 100644 (file)
@@ -737,6 +737,21 @@ static void *mlx_kem_dup(const void *vkey, int selection)
         || (ret = OPENSSL_memdup(key, sizeof(*ret))) == NULL)
         return NULL;
 
+    if (ret->propq != NULL
+        && (ret->propq = OPENSSL_strdup(ret->propq)) == NULL) {
+        OPENSSL_free(ret);
+        return NULL;
+    }
+
+    /* Absent key material, nothing left to do */
+    if (ret->mkey == NULL) {
+        if (ret->xkey == NULL)
+            return ret;
+        /* Fail if the source key is an inconsistent state */
+        OPENSSL_free(ret);
+        return NULL;
+    }
+
     switch (selection & OSSL_KEYMGMT_SELECT_KEYPAIR) {
     case 0:
         ret->xkey = ret->mkey = NULL;