You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: accepting incoming tcp connection x86 Android
With Rust 1.49.0, accepting incoming connections on tcp sockets failed
in different ways:
Starting with Android Oreo (8), Android started using a seccomp based
filter approach to syscalls, explicitly allowing syscalls, see
https://android-developers.googleblog.com/2017/07/seccomp-filter-in-android-o.html.
https://android.googlesource.com/platform/bionic.git/+/master/libc/SYSCALLS.TXT
enumerates the allowed syscalls.
rust-lang/rust#78572 refactored the way
`std::net::TcpListener` accepts incoming connections on tcp sockets.
With the seccomp profile above, doing a generic syscall will result in a
panic:
```
[..]
02-22 13:14:23.288 6015 6041 F my.app.DEBUG: signal 31 (SIGSYS), code
1 (SYS_SECCOMP), fault addr --------
02-22 13:14:23.288 6015 6041 F my.app.DEBUG: Cause: seccomp prevented
call to disallowed x86 system call 364
02-22 13:14:23.289 6015 6041 F my.app.DEBUG: Abort message: 'Fatal
signal 31 (SIGSYS), code 1 (SYS_SECCOMP) in tid 4784 (tokio-runtime-w),
pid 4735 (ground_services)'
```
On top of that, I found that older versions of Android, such as Android
6 (our Zebra ET50), will return Function not implemented (os error 38)
for this syscall. My tests showed that this only happens on x86,
although I can't explain why. Relevant strace:
```
[pid 10918] syscall_364(0x34, 0x9d5c9cf8, 0x9d5c9ca0, 0x80800,
0x9fda9dc8, 0x9fda9dc8 <unfinished ...>
[pid 10918] <... syscall_364 resumed> ) = -1 (errno 38)
```
I have tested this with both real devices as well as Android emulators.
We have been using the `async-io` based `libp2p::tcp::TcpConfig` so far,
which used `std::net::TcpListener` under the hood. This commit also
switches to using `libp2p::tcp::TokioTcpConfig`. Now, tokio uses mio,
which doesn't use `std::net::TcpListener` but raw sockets directly.
Recently, a workaround for the erroneous behaviour described above was
merged to mio, which is still pending to be released on crates.io
(tokio-rs/mio#1462). Once tokio uses the
updated mio version, we should move back to the crates.io provided
version.
For tracking the issue in `std::net::TcpListener`, I created
rust-lang/rust#82400.
0 commit comments