Open LeoneChen opened 1 year ago
Since zero address is under the control of untrusted host, NPD is dangerous for Enclave
If ssl_conn_handle
called before ssl_conn_init
, connectionHandler
can be NULL, since address of TLSConnectionHandler::handle
is from vTable, it is called.
https://github.com/bl4ck5un/mbedtls-SGX/blob/eab8e36a1e670a2fa66105735143eafa51931bff/example/enclave/ecalls.cpp#L44-L46
In TLSConnectionHandler::handle
, this
is NULL, &this->conf
used in memcpy will cause copy from untrusted 0 address
https://github.com/bl4ck5un/mbedtls-SGX/blob/eab8e36a1e670a2fa66105735143eafa51931bff/example/enclave/ssl_conn_hdlr.cpp#L151-L159
Although thread_info
is in,out
, SGX TBridge just pass null to real ECALL
https://github.com/bl4ck5un/mbedtls-SGX/blob/eab8e36a1e670a2fa66105735143eafa51931bff/example/enclave/Enclave.edl#L12
thread_info
is null
https://github.com/bl4ck5un/mbedtls-SGX/blob/eab8e36a1e670a2fa66105735143eafa51931bff/example/enclave/ecalls.cpp#L44-L46
Even if this
is not NULL, thread_info
can be NULL due to lack of check, at line 160 cause NPD
https://github.com/bl4ck5un/mbedtls-SGX/blob/eab8e36a1e670a2fa66105735143eafa51931bff/example/enclave/ssl_conn_hdlr.cpp#L151-L160
UAF 1
If
ssl_conn_handle
called afterssl_conn_teardown
by untrusted host https://github.com/bl4ck5un/mbedtls-SGX/blob/eab8e36a1e670a2fa66105735143eafa51931bff/example/enclave/ecalls.cpp#L44-L50this
is dangling, andthis->conf
at line 159 will cause UAF https://github.com/bl4ck5un/mbedtls-SGX/blob/eab8e36a1e670a2fa66105735143eafa51931bff/example/enclave/ssl_conn_hdlr.cpp#L151-L159UAF 2
If
ssl_conn_teardown
called afterssl_conn_teardown
by untrusted host, second will calldelete connectionHandler;
,srvcert
is freed member varibale InTLSConnectionHandler::~TLSConnectionHandler
, https://github.com/bl4ck5un/mbedtls-SGX/blob/eab8e36a1e670a2fa66105735143eafa51931bff/example/enclave/ssl_conn_hdlr.cpp#L129-L131In
mbedtls_x509_crt_free
. https://github.com/bl4ck5un/mbedtls-SGX/blob/eab8e36a1e670a2fa66105735143eafa51931bff/trusted/mbedtls-2.6.0/library/x509_crt.c#L2346-L2360In
mbedtls_pk_free
, and finallyctx->pk_info
will access already free-edctx
, cause UAF. https://github.com/bl4ck5un/mbedtls-SGX/blob/eab8e36a1e670a2fa66105735143eafa51931bff/trusted/mbedtls-2.6.0/library/pk.c#L66-L74