You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@teaclave.apache.org by Szilárd Parrag <no...@github.com.INVALID> on 2022/11/04 09:24:33 UTC

[apache/incubator-teaclave-sgx-sdk] `bind()` call fails with 'cannot listen on port: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }' (Issue #407)

On the `v1.1.6-testing` branch the `mio` sample code server compiles fine, but will crash runtime:
```
root@14382be3b148:~/sgx/samplecode/mio/server/bin# ./app
[+] Init Enclave Successful 182888297398274!
[+] Test server in enclave, start!
thread '<unnamed>' panicked at 'cannot listen on port: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }', src/lib.rs:443:45
fatal runtime error: failed to initiate panic, error 5
Illegal instruction (core dumped)
```

I compiled it with `SGX_MODE=SW SGX_DEBUG=1 make` inside the `baiduxlab/sgx-rust` container.


Running it via `sgx-gdb`:

[...gdb init messages...]
```
[+] Init Enclave Successful 182905477267458!
[+] Test server in enclave, start!
thread '<unnamed>' panicked at 'cannot listen on port: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }', src/lib.rs:443:45
fatal runtime error: failed to initiate panic, error 5

Program received signal SIGILL, Illegal instruction.
0x00007ff93b6a7ad6 in abort ()
(gdb) bt
#0  0x00007ff93b6a7ad6 in abort ()
#1  0x00007ff93b66f80a in sgx_trts::trts::rsgx_abort () at src/trts.rs:185
#2  0x00007ff93b64c55a in sgx_tstd::sys::abort_internal () at src/sys/mod.rs:144
#3  0x00007ff93b65bf23 in sgx_tstd::panicking::rust_panic (msg=...) at src/panicking.rs:769
#4  0x00007ff93b65bdee in sgx_tstd::panicking::rust_panic_with_hook (payload=..., message=..., location=0x7ff93b744468, can_unwind=true) at src/panicking.rs:737
#5  0x00007ff93b65b72a in rust_begin_unwind (info=0x7ff93b8b5880) at src/panicking.rs:609
#6  0x00007ff93b4d5253 in core::panicking::panic_fmt () at library/core/src/panicking.rs:65
#7  0x00007ff93b4d54b3 in core::result::unwrap_failed () at library/core/src/result.rs:1791
#8  0x00007ff93b4fcc2d in core::result::Result<T,E>::expect (self=..., msg=...) at /rustc/5c8bff74bc1c52bef0c79f3689bb227f51f3e82d/library/core/src/result.rs:1070
#9  0x00007ff93b4fa1a8 in server::run_server (max_conn=30) at src/lib.rs:443
#10 0x00007ff93b4d56a1 in sgx_run_server (pms=0x7ffd18415c7b) at enclave/Enclave_t.c:805
#11 0x00007ff93b4e5b43 in do_ecall () at library/core/src/panicking.rs:203
#12 0x00007ff93b6a73b1 in enter_enclave ()
#13 0x00007ff93b6a778f in enclave_entry ()
#14 0x00007ff93e84c5a8 in __morestack () from /opt/sgxsdk/sdk_libs/libsgx_urts_sim.so
#15 0x00007ff93e8422a2 in CEnclave::ecall(int, void const*, void*, bool) () from /opt/sgxsdk/sdk_libs/libsgx_urts_sim.so
#16 0x00007ff93e8466bf in _sgx_ecall(unsigned long, int, void const*, void*, bool) [clone .part.0] () from /opt/sgxsdk/sdk_libs/libsgx_urts_sim.so
#17 0x00005566c6c0316a in run_server (eid=182905477267458, max_conn=30 '\036') at app/Enclave_u.c:1662
#18 0x00005566c6bff4a7 in app::main () at src/main.rs:81
(gdb)
```

This is what gets passed to the `bind()` call:
```
(gdb) b bind
Function "bind" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (bind) pending.
(gdb) r
Starting program: /root/sgx/samplecode/mio/server/bin/app
warning: Error disabling address space randomization: Operation not permitted
detect urts is loaded, initializing
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
add-symbol-file '/root/sgx/samplecode/mio/server/bin/enclave.signed.so' 0x7f36a799e040 -s .interp 0x7f36a79752e0  -s .note.gnu.build-id 0x7f36a79752fc  -s .gnu.hash 0x7f36a7975320  -s .dynsym 0x7f36a7975358  -s .dynstr 0x7f36a79753e8  -s .gnu.version 0x7f36a797544c  -s .gnu.version_d
 0x7f36a7975458  -s .rela.dyn 0x7f36a7975490  -s .plt 0x7f36a799e000  -s .plt.got 0x7f36a799e010  -s .nipx 0x7f36a7b6ff70  -s .rodata 0x7f36a7b71000  -s .eh_frame_hdr 0x7f36a7bb4614  -s .eh_frame 0x7f36a7bc4e28  -s .gcc_except_table 0x7f36a7c01f8c  -s .tbss 0x7f36a7c0c720  -s .fini_a
rray 0x7f36a7c0c720  -s .data.rel.ro 0x7f36a7c0c740  -s .dynamic 0x7f36a7c1be80  -s .got 0x7f36a7c1c000  -s .data 0x7f36a7c23000  -s .nipd 0x7f36a7c230dc  -s .niprod 0x7f36a7c23100  -s .bss 0x7f36a7c239c0
[+] Init Enclave Successful 183038621253634!
[+] Test server in enclave, start!

Breakpoint 1, bind () at ../sysdeps/unix/syscall-template.S:78
78      ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) up
#1  0x000056267134eddb in sgx_urts::socket::u_bind_ocall (error=0x7fff7dabd688, sockfd=3, address=0x7fff7dabd68c, addrlen=6) at src/socket.rs:70
70          let ret = unsafe { libc::bind(sockfd, address, addrlen) };
(gdb) bt
#0  bind () at ../sysdeps/unix/syscall-template.S:78
#1  0x000056267134eddb in sgx_urts::socket::u_bind_ocall (error=0x7fff7dabd688, sockfd=3, address=0x7fff7dabd68c, addrlen=6) at src/socket.rs:70
#2  0x00005626713488a9 in Enclave_u_bind_ocall (pms=0x7fff7dabd660) at app/Enclave_u.c:1338
#3  0x00007f36aad0af7f in CEnclave::ocall(unsigned int, _ocall_table_t const*, void*) () from /opt/sgxsdk/sdk_libs/libsgx_urts_sim.so
#4  0x00007f36aad15695 in stack_sticker () from /opt/sgxsdk/sdk_libs/libsgx_urts_sim.so
#5  0x00007f36a7b70967 in __morestack ()
#6  0x00007f36a7b70967 in __morestack ()
#7  0x00007f36a79a9a44 in u_bind_ocall (retval=0x7f36a7d7e538, error=0x7f36a7d7e53c, sockfd=3, addr=0x7f36a7d7e5ea, addrlen=6) at enclave/Enclave_t.c:6054
#8  0x00007f36a7b3b73a in sgx_libc::linux::x86_64::ocall::bind (sockfd=3, address=0x7f36a7d7e5ea, addrlen=6) at src/linux/x86_64/ocall.rs:2665
#9  0x00007f36a79daf8b in net2::socket::Socket::bind (self=0x7f36a7d7e7bc, addr=0x7f36a7d7e5e8) at src/socket.rs:35
#10 0x00007f36a79d2856 in net2::tcp::TcpBuilder::bind::{{closure}} (sock=0x7f36a7d7e7bc) at /root/.cargo/git/checkouts/net2-rs-sgx-f838a94cd3806d3c/554583d/src/tcp.rs:55
#11 0x00007f36a79d2693 in net2::tcp::TcpBuilder::with_socket (self=0x7f36a7d7e7b0, f=...) at /root/.cargo/git/checkouts/net2-rs-sgx-f838a94cd3806d3c/554583d/src/tcp.rs:137
#12 0x00007f36a79d2732 in net2::tcp::TcpBuilder::bind (self=0x7f36a7d7e7b0, addr=0x7f36a7d7e9f0) at /root/.cargo/git/checkouts/net2-rs-sgx-f838a94cd3806d3c/554583d/src/tcp.rs:53
#13 0x00007f36a79d35b7 in mio::net::tcp::TcpListener::bind (addr=0x7f36a7d7e9f0) at src/net/tcp.rs:533
#14 0x00007f36a79c3155 in server::run_server (max_conn=30) at src/lib.rs:443
#15 0x00007f36a799e6a1 in sgx_run_server (pms=0x7fff7dabdc5b) at enclave/Enclave_t.c:805
#16 0x00007f36a79aeb43 in do_ecall ()
#17 0x00007f36a7b703b1 in enter_enclave ()
#18 0x00007f36a7b7078f in enclave_entry ()
#19 0x00007f36aad155a8 in __morestack () from /opt/sgxsdk/sdk_libs/libsgx_urts_sim.so
#20 0x00007f36aad0b2a2 in CEnclave::ecall(int, void const*, void*, bool) () from /opt/sgxsdk/sdk_libs/libsgx_urts_sim.so
#21 0x00007f36aad0f6bf in _sgx_ecall(unsigned long, int, void const*, void*, bool) [clone .part.0] () from /opt/sgxsdk/sdk_libs/libsgx_urts_sim.so
#22 0x000056267134916a in run_server (eid=183038621253634, max_conn=30 '\036') at app/Enclave_u.c:1662
#23 0x00005626713454a7 in app::main () at src/main.rs:81
(gdb) info args
error = 0x7fff7dabd688
sockfd = 3
address = 0x7fff7dabd68c
addrlen = 6
(gdb) p *error
$1 = 0
(gdb) p *address
$2 = libc::unix::linux_like::sockaddr {sa_family: 8443, sa_data: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]}
```


If you need more information, please do tell me.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/issues/407
You are receiving this because you are subscribed to this thread.

Message ID: <ap...@github.com>

Re: [apache/incubator-teaclave-sgx-sdk] `bind()` call fails with 'cannot listen on port: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }' (Issue #407)

Posted by Szilárd Parrag <no...@github.com.INVALID>.
Thank you very much @volcano0dr.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/issues/407#issuecomment-1313519643
You are receiving this because you are subscribed to this thread.

Message ID: <ap...@github.com>

Re: [apache/incubator-teaclave-sgx-sdk] `bind()` call fails with 'cannot listen on port: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }' (Issue #407)

Posted by volcano <no...@github.com.INVALID>.
@OverOrion Thanks for reporting this issue, I have fixed it.
root cause: `mio` depends on `net2`, but `net2` is not compatible with rust `nightly-2022-10-22`.
I think a better fix is to update `mio-sgx`.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/issues/407#issuecomment-1304557582
You are receiving this because you are subscribed to this thread.

Message ID: <ap...@github.com>

Re: [apache/incubator-teaclave-sgx-sdk] `bind()` call fails with 'cannot listen on port: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }' (Issue #407)

Posted by Szilárd Parrag <no...@github.com.INVALID>.
Closed #407 as completed.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/issues/407#event-7803055508
You are receiving this because you are subscribed to this thread.

Message ID: <ap...@github.com>