Skip to content

Commit acea48f

Browse files
frkvcvinayak
authored andcommitted
[nrf noup] Fix buffer overread with stream cipher
Recreated from commit faf0b86 which provides the following information "With stream ciphers, add a check that there's enough room to read a MAC in the record. Without this check, subtracting the MAC length from the data length resulted in an integer underflow, causing the MAC calculation to try reading (SIZE_MAX + 1 - maclen) bytes of input, which is a buffer overread." This commit is a "noup" since TLS/DTLS is undergoing refactoring and the content of the commit had to be recreated. Signed-off-by: Frank Audun Kvamtrø <[email protected]>
1 parent 4a204f2 commit acea48f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

library/ssl_msg.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -1330,8 +1330,16 @@ int mbedtls_ssl_decrypt_buf( mbedtls_ssl_context const *ssl,
13301330
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_STREAM)
13311331
if( ssl_mode == MBEDTLS_SSL_MODE_STREAM )
13321332
{
1333+
if (rec->data_len < transform->maclen) {
1334+
MBEDTLS_SSL_DEBUG_MSG(1,
1335+
("Record too short for MAC:"
1336+
" %" MBEDTLS_PRINTF_SIZET " < %" MBEDTLS_PRINTF_SIZET,
1337+
rec->data_len, transform->maclen));
1338+
return MBEDTLS_ERR_SSL_INVALID_MAC;
1339+
}
1340+
13331341
/* The only supported stream cipher is "NULL",
1334-
* so there's nothing to do here.*/
1342+
* so there's no encryption to do here.*/
13351343
}
13361344
else
13371345
#endif /* MBEDTLS_SSL_SOME_SUITES_USE_STREAM */

0 commit comments

Comments
 (0)