]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix OOB read in EC_GROUP_new_from_params() with zero-length generator
authorHarry Betts <harrybetts06@proton.me>
Sat, 9 May 2026 06:54:52 +0000 (16:54 +1000)
committerEugene Syromiatnikov <esyr@openssl.org>
Mon, 11 May 2026 08:32:09 +0000 (10:32 +0200)
When OSSL_PKEY_PARAM_EC_GENERATOR is provided as an octet string of
length 0, buf[0] is read before validating data_size, causing a
heap-buffer-overflow detectable under ASan.

Reject zero-length generator octet strings before the dereference.

CLA: trivial
Resolves: https://github.com/openssl/openssl/issues/31125
Fixes: c0f39ded68ba "Add Explicit EC parameter support to providers."
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Frederik Wedel-Heinen <fwh.openssl@gmail.com>
MergeDate: Mon May 11 08:34:15 2026
(Merged from https://github.com/openssl/openssl/pull/31128)

crypto/ec/ec_lib.c

index 87cd558e323ef68e0c3138af6a1b85951d5643c8..51f0457f65a4fe35c656664e171b2a717d7e1895 100644 (file)
@@ -1731,7 +1731,8 @@ EC_GROUP *EC_GROUP_new_from_params(const OSSL_PARAM params[],
     /* generator base point */
     ptmp = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_EC_GENERATOR);
     if (ptmp == NULL
-        || ptmp->data_type != OSSL_PARAM_OCTET_STRING) {
+        || ptmp->data_type != OSSL_PARAM_OCTET_STRING
+        || ptmp->data_size == 0) {
         ERR_raise(ERR_LIB_EC, EC_R_INVALID_GENERATOR);
         goto err;
     }