Commit 4e9c47a0c1 for openssl.org
commit 4e9c47a0c103cb87262525798b3c6a9965d786b2
Author: Daniel Kubec <kubec@openssl.foundation>
Date: Tue Nov 10 14:28:58 2026 +0100
Fix out-of-bounds read of suiteb_curves[] in TLS 1.3 key_share selection
In Suite B mode tls1_get_supported_groups() replaces the configured
supported-groups list with the fixed two-element suiteb_curves[] array, but
tls1_get_group_tuples() kept returning the tuples derived from the configured
group list. The two functions therefore disagreed: the group-selection walk in
tls_parse_ctos_key_share() advanced first_group_in_tuple through the short
suiteb_curves[] array using tuple sizes that summed to the much longer
configured list, so check_overlap()/check_in_list() read past the end of
suiteb_curves[].
Fixes: CVE-2026-35190
Assisted-by: Claude:claude-fable-5-2
Reviewed-by: Mounir Idrassi <mounir.idrassi@idrix.fr>
Reviewed-by: Andrew Dinh <andrewd@openssl.org>
Merge-date: Mon Nov 16 12:24:33 2026
Merged-from: https://github.com/openssl/openssl/pull/33617
diff --git a/ssl/statem/extensions_srvr.c b/ssl/statem/extensions_srvr.c
index cb316f4943..512f677f79 100644
--- a/ssl/statem/extensions_srvr.c
+++ b/ssl/statem/extensions_srvr.c
@@ -813,6 +813,7 @@ int tls_parse_ctos_key_share(SSL_CONNECTION *s, PACKET *pkt,
const size_t *srvrtuples;
uint16_t *first_group_in_tuple;
size_t clnt_num_groups, srvr_num_groups, srvr_num_tuples;
+ size_t srvr_groups_remaining;
PACKET *encoded_pubkey_arr = NULL;
uint16_t *keyshares_arr = NULL;
size_t keyshares_cnt = 0;
@@ -899,10 +900,23 @@ int tls_parse_ctos_key_share(SSL_CONNECTION *s, PACKET *pkt,
* Remark: Selection priority different for client- or server-preference
*/
first_group_in_tuple = (uint16_t *)srvrgroups;
+ srvr_groups_remaining = srvr_num_groups;
for (current_tuple = 0; current_tuple < srvr_num_tuples; current_tuple++) {
size_t number_of_groups_in_tuple = srvrtuples[current_tuple];
int prio_group_idx = 0, candidate_group_idx = 0;
+ /*
+ * The tuple sizes must partition srvrgroups exactly. A tuple larger
+ * than the groups still left means the group and tuple lists have
+ * come from different sources, which is an internal error: stop here
+ * rather than reading past the end of srvrgroups.
+ */
+ if (number_of_groups_in_tuple > srvr_groups_remaining) {
+ SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
+ goto err;
+ }
+ srvr_groups_remaining -= number_of_groups_in_tuple;
+
/* Server or client preference ? */
if (s->options & SSL_OP_SERVER_PREFERENCE) {
/* Server preference */
diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c
index 3488d0a475..c6559cb76f 100644
--- a/ssl/t1_lib.c
+++ b/ssl/t1_lib.c
@@ -220,6 +220,14 @@ static const uint16_t suiteb_curves[] = {
OSSL_TLS_GROUP_ID_secp384r1,
};
+/*
+ * Group tuples matching the Suite B group lists returned by
+ * tls1_get_supported_groups(): a single tuple holding both P-256 and P-384,
+ * or a single tuple holding just one of them.
+ */
+static const size_t suiteb_tuples_both[] = { OSSL_NELEM(suiteb_curves) };
+static const size_t suiteb_tuples_one[] = { 1 };
+
/* Group list string of the built-in pseudo group DEFAULT_SUITE_B */
#define SUITE_B_GROUP_NAME "DEFAULT_SUITE_B"
#define SUITE_B_GROUP_LIST "?secp256r1:?secp384r1",
@@ -869,11 +877,32 @@ void tls1_get_requested_keyshare_groups(SSL_CONNECTION *s, const uint16_t **pgro
}
}
+/*
+ * Set *ptuples to the list of group tuple sizes and *ptupleslen to the number
+ * of tuples. The tuples returned here always partition exactly the group list
+ * returned by tls1_get_supported_groups().
+ */
void tls1_get_group_tuples(SSL_CONNECTION *s, const size_t **ptuples,
size_t *ptupleslen)
{
SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
+ if (tls1_suiteb(s)) {
+ const uint16_t *groups;
+ size_t groupslen;
+
+ /*
+ * In Suite B mode the fixed group list forms a single tuple. Derive
+ * its size from the list tls1_get_supported_groups() actually returns
+ * rather than repeating the Suite B profile selection here.
+ */
+ tls1_get_supported_groups(s, &groups, &groupslen);
+ *ptuples = groupslen == OSSL_NELEM(suiteb_curves) ? suiteb_tuples_both
+ : suiteb_tuples_one;
+ *ptupleslen = 1;
+ return;
+ }
+
if (s->ext.supportedgroups == NULL) {
*ptuples = sctx->ext.tuples;
*ptupleslen = sctx->ext.tuples_len;