ssl_tls13_server: validate supported_versions extension length

Reject versions_len outside [2,254] or not a multiple of 2, per
RFC 8446 §4.2.1 (versions<2..254>) and §3.4 (vector length must be
a multiple of element size). Prevents malformed/truncated version
lists from being parsed as if well-formed.

Fixes #10739

Signed-off-by: Abel Thomas <abeltom.kernel@gmail.com>
This commit is contained in:
Abel Thomas 2026-07-07 13:39:31 +02:00
parent 47e9e61020
commit 5a7fae71cb
No known key found for this signature in database
GPG Key ID: FECB4CFEB7D688B2

View File

@ -782,6 +782,12 @@ static int ssl_tls13_parse_supported_versions_ext(mbedtls_ssl_context *ssl,
MBEDTLS_SSL_CHK_BUF_READ_PTR(p, end, 1);
versions_len = p[0];
/* RFC 8446, Section 4.2.1 (versions<2..254>) and Section 3.4
* (vector length must be a multiple of the element size). */
if ( (versions_len < 2) || (versions_len > 254) || (versions_len % 2 != 0))
return MBEDTLS_ERR_SSL_DECODE_ERROR;
p += 1;
MBEDTLS_SSL_CHK_BUF_READ_PTR(p, end, versions_len);