Implement io_uring wrapping
cover Implement io_uring wrapping
[YOCTO #15244]
Implemented via a combination of intercepting the syscalls as well as trying to use seccomp to prevent the call from working if a user bypasses our syscall wrapper.
David Nyström (1):
ports/linux: Refuse io_uring in the kernel rather than be bypassed by
it
Mark Hatle (2):
ports/linux/pseudo_wrappers: Report io_uring as unsupported in
syscall()
README.security: Describe io_uring refusal and the host fallback
Makefile.in | 1 + README.security | 16 ++ ports/linux/io_uring_syscalls.h | 72 +++++ ports/linux/portdefs.h | 2 + ports/linux/pseudo_io_uring_seccomp.c | 363 ++++++++++++++++++++++++++ ports/linux/pseudo_wrappers.c | 24 ++ pseudo.1 | 79 ++++++ pseudo_util.c | 2 + pseudo_wrappers.c | 11 + test/test-io-uring-deny.c | 267 +++++++++++++++++++ test/test-io-uring-deny.sh | 16 ++ test/test-io-uring-syscall.c | 47 ++++ test/test-io-uring-syscall.sh | 7 + 13 files changed, 907 insertions(+) create mode 100644 ports/linux/io_uring_syscalls.h create mode 100644 ports/linux/pseudo_io_uring_seccomp.c create mode 100644 test/test-io-uring-deny.c create mode 100755 test/test-io-uring-deny.sh create mode 100644 test/test-io-uring-syscall.c create mode 100755 test/test-io-uring-syscall.sh
Signature · 1 line
2.34.1
PATCH 1/3 ports/linux/pseudo_wrappers: Report io_uring as unsupported in syscall()
Operations submitted through an io_uring are carried out by the kernel without passing through libpseudo, so files they create or change are not tracked, and end up with the build user's ownership. libuv, used by nodejs, and the meta-selftest reproducer set up a ring with syscall().
Refuse io_uring_setup(), io_uring_enter() and io_uring_register() with ENOSYS, as a kernel without io_uring does, so callers fall back to the ordinary calls pseudo can see. This doesn't cover callers that make the system call themselves, such as liburing.
test-io-uring-syscall checks that all three fail with ENOSYS under pseudo.
[YOCTO #15244]
AI-Generated: Uses GitHub Copilot
--- ports/linux/pseudo_wrappers.c | 20 +++++++++++++++ test/test-io-uring-syscall.c | 47 +++++++++++++++++++++++++++++++++++ test/test-io-uring-syscall.sh | 7 ++++++ 3 files changed, 74 insertions(+) create mode 100644 test/test-io-uring-syscall.c create mode 100755 test/test-io-uring-syscall.sh
ports/linux/pseudo_wrappers.c +20 -0
@@ -196,6 +196,11 @@ syscall(long number, ...) { && number != SYS_landlock_create_ruleset && number != SYS_landlock_add_rule && number != SYS_landlock_restrict_self +#endif +#ifdef SYS_io_uring_setup + && number != SYS_io_uring_setup + && number != SYS_io_uring_enter + && number != SYS_io_uring_register #endif ) {if (!real_syscall)
@@ -242,6 +247,21 @@ syscall(long number, ...) { }#endif +#ifdef SYS_io_uring_setup +/* Operations submitted through an io_uring never pass through +* libpseudo, so files they create or change aren't tracked +* (YOCTO #15244). Report io_uring as unsupported, as a kernel +* without it does, so callers fall back to ordinary calls. +*/ +if (number == SYS_io_uring_setup || + number == SYS_io_uring_enter || + number == SYS_io_uring_register) { +pseudo_debug (PDBGF_SYSCALL ,"syscall, refusing io_uring.\n" ); + errno =ENOSYS ; +return -1 ; + } +#endif +#ifdef SYS_openat2/* There is a CVE patch (CVE-2025-45582) to tar 1.34 in Centos Stream which * uses syscall to access openat2() and breaks builds if we don't redirect.
test/test-io-uring-syscall.c new file +47 -0
47 lines not on this page · raw message
test/test-io-uring-syscall.sh new file +7 -0
@@ -0,0 +1,7 @@ +#!/bin/sh +# +# SPDX-License-Identifier: LGPL-2.1-only +# +# io_uring through syscall() is reported as unsupported under pseudo. + +./test/test-io-uring-syscall
Signature · 1 line
2.34.1
PATCH 2/3 ports/linux: Refuse io_uring in the kernel rather than be bypassed by it
In reply to Mark HatleFrom: David Nyström <[email protected]>
An LD_PRELOAD wrapper only sees callers which go through libc, and the two most common io_uring users do not. liburing is normally built with CONFIG_NOLIBC and emits syscall instructions of its own; fio inlines one on its submission path. Those callers reach the kernel directly, which means they hold a real ring and can create, rename or unlink files with pseudo recording none of it - and wrong ownership baked into an image is far harder to notice than a failure would have been.
There is also nothing to wrap: libc exports no io_uring entry point at all, so the kernel is the only place the question can be answered. A seccomp filter marks io_uring_setup(), io_uring_enter() and io_uring_register() and answers them with ENOSYS, which is what a kernel built without io_uring says and what every caller worth worrying about already has a fallback for. A build does not need io_uring; it needs pseudo to see the file operations. The filter is inherited across fork() and execve(), so one installation covers an entire build, including the processes libpseudo cannot be loaded into at all - a statically linked program which uses io_uring gets the same clean ENOSYS rather than slipping past unseen.
The mode is chosen by environment variable and logged at every start:
PSEUDO_IO_URING_SECCOMP=0 passthrough, as pseudo behaved before any of
this existed: nothing installed, nothing checked, io_uring works and pseudo does not see what it does.
PSEUDO_IO_URING_SECCOMP=1 deny, and the default if the variable is not
set.
The values are the numbers the variable is set to, so that a further mode can be added later without renumbering the ones already documented. A value which is neither is warned about and treated as the default, since an unreadable setting is no reason to stop recording ownership.
no_new_privs is a precondition, never something this sets. Installing a filter requires either privilege or no_new_privs, and setting the latter suppresses setuid and file capabilities for the process and everything it execs, which in a build stops a sysroot's own setuid helpers working. That is not pseudo's decision to make on an application's behalf, so where it is unset and pseudo is unprivileged no filter can be installed, deny cannot be enforced, and pseudo falls back to passthrough. That fallback is warned about, because a build which quietly stops recording ownership is the failure which surfaces latest.
The warning costs one line for a build rather than one per process: pseudo is preloaded everywhere, and an unconditional line goes down the stderr of whatever is running - "echo test | cat 2>&1" came back as "io_uring: deny test" - so it goes to pseudo's log when there is one and is otherwise said once behind a marker which children inherit. Whether a filter is already in force travels the same way, because asking the kernel would mean issuing an io_uring syscall, which is fatal under an unrelated filter whose action is SECCOMP_RET_KILL. That marker also stops the thousands of processes in a build each stacking another copy, since every filter in the chain is evaluated on every syscall a process makes.
The filter is asked for with TSYNC and with LOG, and without whichever of them the kernel rejects. TSYNC applies it to every thread, which is what the marker recording that a filter is in force claims; LOG has the kernel record each refused call, in the audit log or in the ring buffer where nothing listens to audit, so that the programs in a build which reach for io_uring can be named rather than guessed at. Neither is worth failing the installation over, since gVisor answers EINVAL to LOG with or without TSYNC beside it, as does a kernel older than 4.14 - dropping a rejected flag keeps io_uring refused where insisting on it would hand io_uring back.
The AUDIT_ARCH value is spelled out rather than taken from <linux/audit.h>, which is not always present in a cross sysroot; an architecture missing from that list installs no filter and io_uring reaches the kernel on it unexamined. The syscall numbers come from the sysroot where it has them and from a table of known ABI assignments where it does not, because a native or nativesdk pseudo may run on an architecture other than the one it was built against.
The test asks the only question that matters - whether the three calls really do answer ENOSYS - and it has to set no_new_privs and re-execute itself to ask it, since pseudo will not set it and a filter cannot be installed without it. Arranging the precondition is what makes the answer the same everywhere instead of only on a machine which happened to have it already, which is not most of them.
Everything which is not pseudo's doing is a skip rather than a failure: a kernel with no seccomp to install a filter into, an architecture with no audit value, an io_uring which has been switched off and answers EPERM rather than the ENOSYS deny gives. The one thing reported as a failure is a filter being in force and io_uring working anyway, because that is pseudo not keeping its word. Passthrough is checked as well, and can only fail the test rather than skip it: a filter installed by an ancestor cannot be removed, so where something upstream has already denied io_uring passthrough is simply not reachable.
AI-Generated: Uses Claude (claude-opus-5)
[YOCTO #15244]
Rebased onto master.
PSEUDO_IO_URING_SECCOMP only decides whether the filter is installed.
pseudo's syscall() wrapper refuses io_uring for callers which go through libc whatever it is set to.
The comment saying syscall() doesn't handle io_uring was dropped and the warning, log message, comments and pseudo.1 describe passthrough as no filter, with only direct callers getting through.
The test makes the system calls directly, as liburing does, since syscall() is always refused.
The mode and any problem installing the filter are reported only in the debug output (PSEUDO_DEBUG=c), never to standard error, so the logging helpers and the PSEUDO_IO_URING_WARNED marker were dropped.
--- Makefile.in | 1 + ports/linux/io_uring_syscalls.h | 72 +++++ ports/linux/portdefs.h | 2 + ports/linux/pseudo_io_uring_seccomp.c | 363 ++++++++++++++++++++++++++ ports/linux/pseudo_wrappers.c | 4 + pseudo.1 | 79 ++++++ pseudo_util.c | 2 + pseudo_wrappers.c | 11 + test/test-io-uring-deny.c | 267 +++++++++++++++++++ test/test-io-uring-deny.sh | 16 ++ 10 files changed, 817 insertions(+) create mode 100644 ports/linux/io_uring_syscalls.h create mode 100644 ports/linux/pseudo_io_uring_seccomp.c create mode 100644 test/test-io-uring-deny.c create mode 100755 test/test-io-uring-deny.sh
Makefile.in +1 -0
@@ -135,6 +135,7 @@ $(LIBPSEUDO): $(WRAPOBJS) pseudo_client.o pseudo_client_scanf.o pseudo_ipc.o $(S $(OBJS): pseudo_tables.h pseudo_client.o pseudo_server.o pseudo_ipc.o: pseudo_ipc.h +pseudo_wrappers.o: ports/linux/pseudo_io_uring_seccomp.c ports/linux/io_uring_syscalls.h pseudo_client.o: pseudo_client.h
ports/linux/io_uring_syscalls.h new file +72 -0
72 lines not on this page · raw message
ports/linux/portdefs.h +2 -0
@@ -110,3 +110,5 @@ struct mount_attr;#define SYS_open_tree_attr __NR_open_tree_attr#endif + +#include "io_uring_syscalls.h"
ports/linux/pseudo_io_uring_seccomp.c new file +363 -0
363 lines not on this page · raw message
ports/linux/pseudo_wrappers.c +4 -0
@@ -169,6 +169,10 @@ out:return fd; } +#ifdef PSEUDO_HAVE_IO_URING_SYSCALLS +#include "pseudo_io_uring_seccomp.c" +#endif +long syscall (long number, ...) {long rc =-1 ;
pseudo.1 +79 -0
85 lines not on this page · raw message
pseudo_util.c +2 -0
@@ -58,6 +58,8 @@ static struct pseudo_variables pseudo_env[] = { { "PSEUDO_DISABLED", 15, NULL }, { "PSEUDO_UNLOAD", 13, NULL }, { "PSEUDO_ALLOW_FSYNC", 18, NULL }, + { "PSEUDO_IO_URING_SECCOMP", 23, NULL }, + { "PSEUDO_IO_URING_FILTER", 22, NULL }, #ifdef PSEUDO_PROFILING { "PSEUDO_PROFILE_PATH", 19, NULL }, #endif
pseudo_wrappers.c +11 -0
@@ -65,6 +65,12 @@ static void pseudo_sigblock(sigset_t *);extern char *program_invocation_short_name;static sigset_t pseudo_saved_sigmask; +#if PSEUDO_PORT_LINUX && defined(PSEUDO_HAVE_IO_URING_SYSCALLS ) +/* Defined in ports/linux/pseudo_io_uring_seccomp.c, which is pulled in with +* the rest of the port's wrappers at the bottom of this file. */ +static void pseudo_io_uring_init (void ); +#endif +/* Constructor only exists in libpseudo */ static void _libpseudo_init (void ) __attribute__ ((constructor));
@@ -115,6 +121,11 @@ _libpseudo_init(void) {pseudo_init_wrappers ();pseudo_init_client (); +#if PSEUDO_PORT_LINUX && defined(PSEUDO_HAVE_IO_URING_SYSCALLS ) +/* Needs the real_* pointers and pseudo_disabled, so it goes last. */ +pseudo_io_uring_init (); +#endif +pseudo_magic ();pseudo_droplock (); }
test/test-io-uring-deny.c new file +267 -0
267 lines not on this page · raw message
test/test-io-uring-deny.sh new file +16 -0
@@ -0,0 +1,16 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1-only +# +# Deny is the default, so the first run says nothing about the mode. It sets +# no_new_privs itself, so it is checked whatever the machine does about that, +# and it decides the result: a skip here means this kernel or architecture has +# no filter to put in force. +./test/test-io-uring-deny deny +case $? in 0);; 77) exit 255;; *) exit 1;; esac +# Passthrough can only fail the test, not skip it. A filter installed by an +# ancestor cannot be removed, so where something upstream of the test has +# already denied io_uring - including pseudo itself, when it was started +# somewhere no_new_privs was already set - passthrough is not reachable, and +# the run above is what there was to check. +PSEUDO_IO_URING_SECCOMP=0 ./test/test-io-uring-deny passthrough +case $? in 0 | 77);; *) exit 1;; esac
Signature · 1 line
2.34.1
PATCH 3/3 README.security: Describe io_uring refusal and the host fallback
In reply to Mark HatleExplain that pseudo refuses io_uring because it can't see the file operations done through it, and that its seccomp filter needs no_new_privs. Where that isn't available, or io_uring should be ruled out for every process on the build host, the kernel.io_uring_disabled sysctl can disable it.
[YOCTO #15244]
AI-Generated: Uses GitHub Copilot
--- README.security | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
README.security +16 -0
@@ -38,6 +38,20 @@ started pseudo. This includes: A program running under pseudo can therefore always step outside of it. pseudo cannot be used to restrict what a program does. +Files created or changed through io_uring are not seen by pseudo, so +pseudo refuses io_uring: calls made through syscall() always fail with +ENOSYS, and by default (PSEUDO_IO_URING_SECCOMP, see pseudo.1) a seccomp +filter also refuses calls made directly, such as liburing's. The filter +can only be installed where no_new_privs is already set. Where it is +not, or to rule io_uring out for every process on the build host, +including those pseudo is not loaded into, disable io_uring in the +kernel instead: +on Linux 6.6 and later, and some distribution kernels, the sysctl +kernel.io_uring_disabled=2 makes io_uring_setup() fail with EPERM for +everyone, and kernel.io_uring_disabled=1 limits it to CAP_SYS_ADMIN and +members of kernel.io_uring_group. The default seccomp profiles of +container runtimes such as Docker also refuse io_uring. + 2. "ROOT" EXISTS ONLY IN THE DATABASE
@@ -167,3 +181,5 @@ RECOMMENDATIONS: ownership and mode. * Verify the ownership, permissions, labels and capabilities of security relevant files in the final image. +* Where pseudo cannot install its io_uring filter, disable io_uring on + the build host with the kernel.io_uring_disabled sysctl.
Signature · 1 line
2.34.1