The _nx_secure_tls_psk_identity_find() function is called to compare a psk identity string (that is extracted from a TLS hello client message) with identities that the TLS stack knows about. It loops over all the identities it knows about and performs a memcmp() for each stored identity, compared against the client hello provided identity. The length field used is the client hello provided length. There is no check to see if the client hello provided identity length is larger than the stored identity. If the client provided identity length is larger, an out of bound read could occur.
Given that memcmp() is used, and the length is controlled by a potential attacker, it could be used to brute force out of bound memory one byte at a time, causing an effective info leak. Should keys be stored in continuous memory, this issue could be used by an attack to recover keys.
It should be noted that there is a length check, however, the length check only occurs AFTER the call the memcmp().
code:
threadx\netxduo-master\nx_secure\src\nx_secure_tls_psk_identity_find.c
UINT _nx_secure_tls_psk_identity_find(NX_SECURE_TLS_SESSION *tls_session, UCHAR **psk_data, UINT *psk_length,
UCHAR *psk_identity, UINT identity_length, UINT *psk_store_index)
{
UINT psk_list_size;
UINT compare_val;
UINT i;
...
for (i = 0; i < psk_list_size; ++i)
{
/* Save off the PSK and its length. */
compare_val = (UINT)NX_SECURE_MEMCMP(tls_session -> nx_secure_tls_credentials.nx_secure_tls_psk_store[i].nx_secure_tls_psk_id, psk_identity, identity_length); // <-- could read out of bound if psk_identity length > nx_secure_tls_credentials.nx_secure_tls_psk_store[i].nx_secure_tls_psk_id length
/* See if the identity matched, and the length is the same (without the length, we could have a
matching prefix which could be a possible attack vector... */
if (compare_val == 0 && identity_length == tls_session -> nx_secure_tls_credentials.nx_secure_tls_psk_store[i].nx_secure_tls_psk_id_size) // <-- this length check is too late. It should happen _BEFORE_ the memcmp
{
...
}
}
...
}
The
_nx_secure_tls_psk_identity_find()function is called to compare a psk identity string (that is extracted from a TLS hello client message) with identities that the TLS stack knows about. It loops over all the identities it knows about and performs amemcmp()for each stored identity, compared against the client hello provided identity. The length field used is the client hello provided length. There is no check to see if the client hello provided identity length is larger than the stored identity. If the client provided identity length is larger, an out of bound read could occur.Given that
memcmp()is used, and the length is controlled by a potential attacker, it could be used to brute force out of bound memory one byte at a time, causing an effective info leak. Should keys be stored in continuous memory, this issue could be used by an attack to recover keys.It should be noted that there is a length check, however, the length check only occurs AFTER the call the
memcmp().code: