Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several Bugs #24

Open
LeoneChen opened this issue Apr 29, 2023 · 2 comments
Open

Several Bugs #24

LeoneChen opened this issue Apr 29, 2023 · 2 comments

Comments

@LeoneChen
Copy link

LeoneChen commented Apr 29, 2023

UAF 1

If ssl_conn_handle called after ssl_conn_teardown by untrusted host

void ssl_conn_handle(long int thread_id, thread_info_t* thread_info) {
connectionHandler->handle(thread_id, thread_info);
}
void ssl_conn_teardown(void) {
delete connectionHandler;
}

this is dangling, and this->conf at line 159 will cause UAF
void TLSConnectionHandler::handle(long int thread_id, thread_info_t *thread_info) {
int ret, len;
mbedtls_net_context *client_fd = &thread_info->client_fd;
unsigned char buf[1024];
mbedtls_ssl_context ssl;
// thread local data
mbedtls_ssl_config conf;
memcpy(&conf, &this->conf, sizeof(mbedtls_ssl_config));

UAF 2

If ssl_conn_teardown called after ssl_conn_teardown by untrusted host, second will call delete connectionHandler;, srvcert is freed member varibale
In TLSConnectionHandler::~TLSConnectionHandler,

TLSConnectionHandler::~TLSConnectionHandler() {
mbedtls_x509_crt_free(&srvcert);
mbedtls_pk_free(&pkey);

In mbedtls_x509_crt_free.

void mbedtls_x509_crt_free( mbedtls_x509_crt *crt )
{
mbedtls_x509_crt *cert_cur = crt;
mbedtls_x509_crt *cert_prv;
mbedtls_x509_name *name_cur;
mbedtls_x509_name *name_prv;
mbedtls_x509_sequence *seq_cur;
mbedtls_x509_sequence *seq_prv;
if( crt == NULL )
return;
do
{
mbedtls_pk_free( &cert_cur->pk );

In mbedtls_pk_free, and finally ctx->pk_info will access already free-ed ctx, cause UAF.

void mbedtls_pk_free( mbedtls_pk_context *ctx )
{
if( ctx == NULL || ctx->pk_info == NULL )
return;
ctx->pk_info->ctx_free_func( ctx->pk_ctx );
mbedtls_zeroize( ctx, sizeof( mbedtls_pk_context ) );
}

@LeoneChen
Copy link
Author

LeoneChen commented Apr 30, 2023

Null Pointer Dereference

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.

void ssl_conn_handle(long int thread_id, thread_info_t* thread_info) {
connectionHandler->handle(thread_id, thread_info);
}

In TLSConnectionHandler::handle, this is NULL, &this->conf used in memcpy will cause copy from untrusted 0 address

void TLSConnectionHandler::handle(long int thread_id, thread_info_t *thread_info) {
int ret, len;
mbedtls_net_context *client_fd = &thread_info->client_fd;
unsigned char buf[1024];
mbedtls_ssl_context ssl;
// thread local data
mbedtls_ssl_config conf;
memcpy(&conf, &this->conf, sizeof(mbedtls_ssl_config));

@LeoneChen LeoneChen changed the title Two UAF Bugs Several Bugs Apr 30, 2023
@LeoneChen
Copy link
Author

LeoneChen commented Apr 30, 2023

Null Pointer Dereference

Although thread_info is in,out, SGX TBridge just pass null to real ECALL

public void ssl_conn_handle(long int thread_id, [in,out] thread_info_t* thread_info);

thread_info is null

void ssl_conn_handle(long int thread_id, thread_info_t* thread_info) {
connectionHandler->handle(thread_id, thread_info);
}

Even if this is not NULL, thread_info can be NULL due to lack of check, at line 160 cause NPD

void TLSConnectionHandler::handle(long int thread_id, thread_info_t *thread_info) {
int ret, len;
mbedtls_net_context *client_fd = &thread_info->client_fd;
unsigned char buf[1024];
mbedtls_ssl_context ssl;
// thread local data
mbedtls_ssl_config conf;
memcpy(&conf, &this->conf, sizeof(mbedtls_ssl_config));
thread_info->config = &conf;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant