Skip to content

Commit

Permalink
fix: accepting incoming tcp connection x86 Android
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wngr committed Feb 22, 2021
1 parent 9237d85 commit c04d2f4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ futures = { version = "0.3.12", package = "futures" }
serde = { version = "1.0.123", features = ["derive"] }
serde_json = { version = "1.0.61", features = ["raw_value"] }
bytes = "1.0.1"
tokio = { version = "1.1.0", features = ["full"], package = "tokio" }
tokio = { version = "1.2.0", features = ["full"], package = "tokio" }
tracing = "0.1.22"
tracing-futures = "0.2.4"
actyxos_sdk = { path = "../../rust/sdk" }
Expand Down

0 comments on commit c04d2f4

Please sign in to comment.