quinn icon indicating copy to clipboard operation
quinn copied to clipboard

fix(udp): use libc::recvmmsg on Android x86

Open mxinden opened this issue 1 year ago • 2 comments

On x86-32, socketcall() was historically the only entry point for the sockets API. However, starting in Linux 4.3, direct system calls are provided on x86-32 for the sockets API.

https://man7.org/linux/man-pages/man2/socketcall.2.html

Androids x86 even goes as far as automatically dispatching advanced socket calls (e.g. socket or recvmmsg) through socketcall in its Bionic libc:

For example, socket() syscall on i386 actually becomes: socketcall(__NR_socket, 1, *(rest of args on stack)).

https://android.googlesource.com/platform/bionic/+/refs/tags/android-vts-14.0_r5/libc/SYSCALLS.TXT#19

In addition Android enables seccomp filtering since Android 8:

https://android-developers.googleblog.com/2017/07/seccomp-filter-in-android-o.html

Currently quinn-udp calls recvmmsg directly on Android x86:

https://github.com/quinn-rs/quinn/blob/c0b1e281e3167d4f4c8496082cb1117c4a270ad8/quinn-udp/src/unix.rs#L447-L448

A direct recvmmsg through libc::syscall(libc::SYS_recvmmsg does not trigger the automatic Android x86 Bionic libc dispatch logic through socketcall, but instead calls the unimplemented recvmmsg syscall. Instead of triggering a libc::ENOSYS, seccomp disallows the call, thus leading to a panic of the application.

This commit changes quinn-udp to use libc::recvmmsg on Android x86, thus leveraging Bionic's automatic dispatch of recvmmsg through socketcall.

Note that this commit only uses libc::recvmmsg on Android x86, not any other Android or Linux variant. Thus quinn-udp would still support missing libc::recvmmsg on those systems. See https://github.com/quinn-rs/quinn/pull/1504.


Fixes #1947.

Problem itself and fix reproducible on Firefox CI. See e.g. latest CI run startup-x86.

Still unable to reproduce via https://github.com/quinn-rs/quinn/pull/1950. I assume this is due to still using a 64bit toolchain when testing x86.

//CC @link2xt following up on https://github.com/quinn-rs/quinn/pull/1504, this might be of interest for you.

mxinden avatar Aug 10 '24 09:08 mxinden