Browse Source

[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().
Dmitrii Kuvaiskii 6 years ago
parent
commit
76fa183257
1 changed files with 13 additions and 11 deletions
  1. 13 11
      Pal/src/host/Linux-SGX/sgx_enclave.c

+ 13 - 11
Pal/src/host/Linux-SGX/sgx_enclave.c

@@ -378,18 +378,20 @@ static int sgx_ocall_sock_connect(void * pms)
             goto err_fd;
     }
 
-    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 (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))
-        goto err_fd;
+        if (IS_ERR(ret))
+            goto err_fd;
+    }
 
     if (ms->ms_bind_addr && !ms->ms_bind_addr->sa_family) {
         socklen_t addrlen;