Merge pull request #1654 from bjwtaylor/ECDHE-PSK-integer-overflow-restricted-3.6

Backport for Ecdhe psk integer overflow fix to 3.6
This commit is contained in:
Gilles Peskine 2026-06-16 11:50:01 +02:00 committed by GitHub
commit 364f07a926
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 2 deletions

View File

@ -0,0 +1,3 @@
Security
* Fix a remote buffer overflow in (D)TLS with ECDHE-PSK cipher suites when
CBC is disabled. Reported by Karnakar Reddy. CVE-ID-50580

View File

@ -2994,11 +2994,16 @@ ecdh_calc_secret:
/* uint16 to store content length */
const size_t content_len_size = 2;
const size_t ecpoint_len_size = 1;
const size_t ecpoint_max_len =
PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(handshake->xxdh_psa_type,
handshake->xxdh_psa_bits);
header_len = 4;
if (header_len + content_len_size + ssl->conf->psk_identity_len
> MBEDTLS_SSL_OUT_CONTENT_LEN) {
if (ecpoint_max_len > MBEDTLS_SSL_OUT_CONTENT_LEN - ecpoint_len_size ||
header_len + content_len_size + ssl->conf->psk_identity_len
> MBEDTLS_SSL_OUT_CONTENT_LEN - ecpoint_len_size - ecpoint_max_len) {
MBEDTLS_SSL_DEBUG_MSG(1,
("psk identity too long or SSL buffer too short"));
return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL;

View File

@ -8922,6 +8922,37 @@ run_test "DHM size: server default, client 2049, rejected" \
1 \
-c "DHM prime too short:"
# Miscellaneous PSK-related tests
psk_identity_max_minus_10=a$(printf "%$((MAX_OUT_LEN - 11))s" z | tr ' ' .)
run_test "Large PSK identity (MBEDTLS_SSL_OUT_CONTENT_LEN - 7)" \
"$P_SRV debug_level=3 \
psk_identity=${psk_identity_max_minus_10}987 psk=73776f726466697368" \
"$P_CLI force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA256 debug_level=3 \
psk_identity=${psk_identity_max_minus_10}987 psk=73776f726466697368" \
1 \
-s "! mbedtls_ssl_handshake returned" \
-c "! mbedtls_ssl_handshake returned"
run_test "Large PSK identity (MBEDTLS_SSL_OUT_CONTENT_LEN - 6)" \
"$P_SRV debug_level=3 \
psk_identity=${psk_identity_max_minus_10}9876 psk=73776f726466697368" \
"$P_CLI force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA256 debug_level=3 \
psk_identity=${psk_identity_max_minus_10}9876 psk=73776f726466697368" \
1 \
-s "! mbedtls_ssl_handshake returned" \
-c "! mbedtls_ssl_handshake returned"
run_test "Large PSK identity (MBEDTLS_SSL_OUT_CONTENT_LEN - 5)" \
"$P_SRV debug_level=3 \
psk_identity=${psk_identity_max_minus_10}98765 psk=73776f726466697368" \
"$P_CLI force_ciphersuite=TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA256 debug_level=3 \
psk_identity=${psk_identity_max_minus_10}98765 psk=73776f726466697368" \
1 \
-s "! mbedtls_ssl_handshake returned" \
-c "! mbedtls_ssl_handshake returned"
# Tests for PSK callback
run_test "PSK callback: psk, no callback" \