As we known, all the value OCALL returns is untrusted. mbedtls_net_accept_ocall is a wrapper function of OCALL function ocall_mbedtls_net_accept. mbedtls_net_accept_ocall should have checked whether the value returned from ocall_mbedtls_net_accept is valid, E.g., the ip_len should always less than or equal to buf_size.
Missing the check means the callee takes the responsibility to check returned value. Unfortunately, in example/enclave/s_server.c, the sample code doesn't check the value returned from mbedtls_net_accept_ocall, which will cause a stack memory leak.
The code above invokes mbedtls_net_accept_ocall to get client_ip and cliip_len at first, then it invokes mbedtls_ssl_set_client_transport_id to store client_ip with length of cliip_len. The cliip_len is returned from OCALL and there is no check on it. If the attacker returns cliip_len that is larger than sizeof(client_ip), mbedtls_ssl_set_client_transport_id will store larger size of contents than client_ip should be. That's a stack memory leak.
To fix this issue, we can implement a wrapper function in enclave. It invokes mbedtls_net_accept_ocall and check returned ip_len.
I found a implementation issue in
ocall_mbedtls_net_accept
that will casue a vulnerability.This is the definition in EDL.
As we known, all the value OCALL returns is untrusted.
mbedtls_net_accept_ocall
is a wrapper function of OCALL functionocall_mbedtls_net_accept
.mbedtls_net_accept_ocall
should have checked whether the value returned fromocall_mbedtls_net_accept
is valid, E.g., theip_len
should always less than or equal to buf_size.Missing the check means the callee takes the responsibility to check returned value. Unfortunately, in
example/enclave/s_server.c
, the sample code doesn't check the value returned frommbedtls_net_accept_ocall
, which will cause a stack memory leak.The code above invokes
mbedtls_net_accept_ocall
to getclient_ip
andcliip_len
at first, then it invokesmbedtls_ssl_set_client_transport_id
to storeclient_ip
with length ofcliip_len
. Thecliip_len
is returned from OCALL and there is no check on it. If the attacker returnscliip_len
that is larger thansizeof(client_ip)
,mbedtls_ssl_set_client_transport_id
will store larger size of contents thanclient_ip
should be. That's a stack memory leak.To fix this issue, we can implement a wrapper function in enclave. It invokes
mbedtls_net_accept_ocall
and check returnedip_len
.