From 76fa1832579b7878541b34ab7b4864df4e253385 Mon Sep 17 00:00:00 2001 From: Dmitrii Kuvaiskii Date: Fri, 3 May 2019 12:24:41 -0700 Subject: [PATCH] [Pal/Linux-SGX] Fix UDP bug with connect() in sgx_ocall_sock_connect() Before, connect() host-OS syscall was issued unconditionally in sgx_ocall_sock_connect(). However, UDP clients do not strictly need to issue connect() before sending packets to UDP server. In this case, addr is NULL, and sgx_ocall_sock_connect() must not issue connect(). --- Pal/src/host/Linux-SGX/sgx_enclave.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Pal/src/host/Linux-SGX/sgx_enclave.c b/Pal/src/host/Linux-SGX/sgx_enclave.c index aaf33731..8b62872a 100644 --- a/Pal/src/host/Linux-SGX/sgx_enclave.c +++ b/Pal/src/host/Linux-SGX/sgx_enclave.c @@ -378,19 +378,21 @@ static int sgx_ocall_sock_connect(void * pms) goto err_fd; } - ret = INLINE_SYSCALL(connect, 3, fd, ms->ms_addr, ms->ms_addrlen); + if (ms->ms_addr) { + ret = INLINE_SYSCALL(connect, 3, fd, ms->ms_addr, ms->ms_addrlen); - if (IS_ERR(ret) && ERRNO(ret) == EINPROGRESS) { - do { - struct pollfd pfd = { .fd = fd, .events = POLLOUT, .revents = 0, }; - ret = INLINE_SYSCALL(ppoll, 4, &pfd, 1, NULL, NULL); - } while (IS_ERR(ret) && - ERRNO(ret) == -EWOULDBLOCK); + if (IS_ERR(ret) && ERRNO(ret) == EINPROGRESS) { + do { + struct pollfd pfd = { .fd = fd, .events = POLLOUT, .revents = 0, }; + ret = INLINE_SYSCALL(ppoll, 4, &pfd, 1, NULL, NULL); + } while (IS_ERR(ret) && + ERRNO(ret) == -EWOULDBLOCK); + } + + if (IS_ERR(ret)) + goto err_fd; } - if (IS_ERR(ret)) - goto err_fd; - if (ms->ms_bind_addr && !ms->ms_bind_addr->sa_family) { socklen_t addrlen; ret = INLINE_SYSCALL(getsockname, 3, fd, ms->ms_bind_addr,