From: bot+bpf-ci@kernel.org
To: jarkko@kernel.org,linux-fsdevel@vger.kernel.org
Cc: jarkko@kernel.org,bpf@vger.kernel.org,containers@lists.linux.dev,linux-api@vger.kernel.org,linux-arch@vger.kernel.org,linux-doc@vger.kernel.org,linux-kernel@vger.kernel.org,linux-kselftest@vger.kernel.org,linux-mm@kvack.org,linux-security-module@vger.kernel.org,aleksa@amutable.com,alex@amutable.com,viro@zeniv.linux.org.uk,luto@amacapital.net,arnd@arndb.de,brauner@kernel.org,dhowells@redhat.com,ebiggers@kernel.org,giuseppe@scrivano.org,hughd@google.com,jack@suse.cz,jlayton@kernel.org,corbet@lwn.net,josef@toxicpanda.com,kees@kernel.org,kpsingh@kernel.org,lennart@poettering.net,neal@gompa.dev,oleg@redhat.com,paul@paul-moore.com,ptikhomirov@virtuozzo.com,sergeh@kernel.org,skhan@linuxfoundation.org,zygmunt.krynicki@canonical.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [RFC PATCH v7 25/26] selftests/userland: Add userland test suite
Date: Sun, 22 Nov 2026 20:28:05 +0000 (UTC) [thread overview]
Message-ID: <ceb256f2afc7fa8c469f5f235f1e77aed593945868918788bc32ad76dee810ae@mail.kernel.org> (raw)
In-Reply-To: <20261122193539.3334213-26-jarkko@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 7234 bytes --]
> selftests/userland: Add userland test suite
TL;DR:
- Selftest run as root may propagate a tmpfs over the host's /tmp and leave it
mounted
- Python 3.9-3.11 fails instead of skipping (os.unshare/setns need 3.12)
- E2BIG check may fail on 64K-page kernels
> diff --git a/tools/testing/selftests/userland/test_smoke.sh b/tools/testing/selftests/userland/test_smoke.sh
> new file mode 100755
> --- /dev/null
> +++ b/tools/testing/selftests/userland/test_smoke.sh
> @@ -0,0 +1,10 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0
> +
> +# Kselftest framework requirement - SKIP code is 4.
> +ksft_skip=4
> +
> +command -v python3 >/dev/null 2>&1 || exit $ksft_skip
> +
> +DIR="$(dirname "$(readlink -f "$0")")"
> +exec python3 "$DIR/userland_test.py" "$@"
Does this wrapper need to check for more than the presence of python3?
userland_test.py calls os.unshare() and os.setns() at many sites, and both
functions first appeared in Python 3.12. Documentation/process/changes.rst
gives Python 3.9 as the minimum. On a 3.9 to 3.11 interpreter, with a
kernel that has CONFIG_USERLAND=y, the tests that reach those calls raise
AttributeError. Inside Userland.run() the child does:
except BaseException:
os._exit(126)
so the test only reports assertEqual(126, 0), KtapRunner.main() exits with
KSFT_FAIL, and the run is recorded as "not ok" rather than skipped. Since
the Makefile change adds userland to the default TARGETS, a default
"make kselftest" would show these failures on such hosts.
Would a check like this be more appropriate:
python3 -c 'import os, sys; sys.exit(not (hasattr(os, "unshare") and hasattr(os, "setns")))' || exit $ksft_skip
or an equivalent hasattr() check in KtapRunner.main() that exits with
KSFT_SKIP?
[ ... ]
> diff --git a/tools/testing/selftests/userland/userland_test.py b/tools/testing/selftests/userland/userland_test.py
[ ... ]
> + @classmethod
> + def enter_foreign_pidns(cls, rns: Userland) -> None:
> + with cls.closing_fd(rns.get_nsfd(CloneFlag.NEWUSER)) as ufd:
> + os.setns(ufd, CloneFlag.NEWUSER)
> + os.unshare(CloneFlag.NEWPID)
A subsystem pattern flags this as potentially concerning: a selftest should
not exit with a failure status when a prerequisite is missing, and should
skip instead.
os.setns() and os.unshare() are only available from Python 3.12, so on
Python 3.9 to 3.11 these calls raise AttributeError even though the kernel
is fully configured. enter_foreign_pidns() is reached from
test_clone_flags_and_pidns_ancestry() through check_exdev(), and
check_dead_ancestor_pidns() calls os.unshare(CloneFlag.NEWPID) directly.
Both run under run_forked(), whose "except BaseException" turns the
AttributeError into a failure payload, so the result is "not ok" and a
KSFT_FAIL exit instead of a skip.
The kernel-side prerequisites are handled through SKIP_ERRNOS and
probe_pre_idmap_mkdir(), and the interpreter requirement is the only gap.
The Sys helper already calls the other syscalls through ctypes, so would
routing setns and unshare through libc the same way, for example
Sys._LIBC.setns and Sys._LIBC.unshare, remove the 3.12 dependency? The
alternative is to skip when hasattr(os, "setns") is false.
[ ... ]
> + def check_child_src_slave_locking() -> None:
> + self.enter_userns_if_unpriv()
> + os.unshare(CloneFlag.NEWNS)
> + with self.closing_fd(self.make_plain_mount("tmpfs")) as tfd:
> + os.mkdir("sub", 0o755, dir_fd=tfd)
> + Sys.move_mount(
> + tfd,
> + "",
> + Sys.AT_FDCWD,
> + "/tmp",
> + MoveMountFlag.F_EMPTY_PATH,
> + )
Can this leave a tmpfs mounted over the host's /tmp when the suite runs as
root?
When euid is 0, enter_userns_if_unpriv() returns without creating a user
namespace:
def enter_userns_if_unpriv(cls) -> None:
if os.geteuid() == 0:
return
so os.unshare(CloneFlag.NEWNS) creates a mount namespace in init_user_ns.
copy_mnt_ns() only adds CL_SLAVE when the user namespace changes:
if (user_ns != ns->user_ns)
copy_flags |= CL_SLAVE;
Without CL_SLAVE the copied mounts remain peers of the host mounts. On a
systemd host / is shared and /tmp is usually a separate shared mount, and
nothing in the runner or setUp() makes the mounts private.
The move_mount() onto /tmp then reaches attach_recursive_mnt() with a shared
dest_mnt:
if (IS_MNT_SHARED(dest_mnt)) {
err = invent_group_ids(source_mnt, true);
...
err = propagate_mnt(dest_mnt, dest_mp, source_mnt, &tree_list);
}
so a copy of the tmpfs is propagated on top of the host's /tmp. The
cleanup at the end of the helper is only:
Sys.umount2("/tmp/sub", UmountFlag.DETACH)
and when the run_forked() child exits, put_mnt_ns() calls
umount_tree(ns->root, 0) without UMOUNT_PROPAGATE, so the propagated copy
stays in the host namespace. After one root run, the real /tmp contents
(for example /tmp/.X11-unix/X0 or tmux and ssh-agent sockets) would be hidden
behind an empty tmpfs until it is unmounted by hand. If the test fails
between the T_MNTNS move_mount() and the final umount2(), a propagated
/tmp/sub is left behind as well.
check_standalone_mntns() in test_pivot_root_and_standalone_mntns_hot_mount()
already guards against this:
os.unshare(CloneFlag.NEWNS)
Sys.set_mount_propagation("/")
Should check_child_src_slave_locking() call Sys.set_mount_propagation("/")
(MS_REC|MS_PRIVATE) right after os.unshare(CloneFlag.NEWNS)? The later
set_mount_propagation("/tmp", MountFlag.REC | MountFlag.SHARED) would then
create a peer group local to the test namespace, and the slave locking
scenario would still be exercised.
[ ... ]
> + big_buf = ctypes.create_string_buffer(65536)
> + with self.assertRaises(OSError) as cm:
> + Sys.userns_set_idmap_raw(
> + userns_fd, ctypes.addressof(big_buf), size=65536
> + )
> + self.assertEqual(cm.exception.errno, errno.E2BIG)
Does this oversized-struct check assume PAGE_SIZE is below 64 KiB?
sys_userns_set_idmap() only returns -E2BIG when size is larger than
PAGE_SIZE:
if (unlikely(size > PAGE_SIZE))
return -E2BIG;
On 64K page kernels (PPC_64K_PAGES is the default for PPC_BOOK3S_64, and
arm64 has ARM64_64K_PAGES), size == PAGE_SIZE, so that branch is skipped.
copy_struct_from_user() then finds the trailing bytes zeroed, req is all
zeros, and the syscall returns -EINVAL from the check on
nr_uid_extents, nr_gid_extents and nr_projid_extents. The
assertEqual(..., errno.E2BIG) would then fail on those systems, which
Sys._build_syscall_numbers() explicitly supports.
Would a size derived from the runtime page size, for example
mmap.PAGESIZE + 1 with a buffer of that size, hit the E2BIG branch on every
page size?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45063222848
next prev parent reply other threads:[~2026-11-22 20:28 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 19:35 [RFC PATCH v7 00/26] userland: Userland containers Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 01/26] userns: Factor out idmap validation and commit helpers Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 02/26] userns: Add userns_set_idmap() system call Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 03/26] arch: Wire up " Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 04/26] mount: Add mnt_ns_get_root() Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 05/26] mount: Enforce mount_too_revealing() for foreign mntns Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 06/26] mount: Support MOVE_MOUNT_T_MNTNS in move_mount() Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 07/26] mount: Support MOVE_MOUNT_CLONE with MOVE_MOUNT_T_MNTNS Jarkko Sakkinen
2026-11-22 20:28 ` bot+bpf-ci
2026-11-22 19:35 ` [RFC PATCH v7 08/26] userns: Factor out install_user_ns_cred() Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 09/26] nsproxy: Expose create_new_namespaces() Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 10/26] userland: Add core infrastructure Jarkko Sakkinen
2026-11-22 20:28 ` bot+bpf-ci
2026-11-22 19:35 ` [RFC PATCH v7 11/26] userland: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
2026-11-22 20:09 ` bot+bpf-ci
2026-11-22 19:35 ` [RFC PATCH v7 12/26] userland: Add userland_open() system call Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 13/26] userland: Add USERLAND_GET_NSFD ioctl Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 14/26] userland: Add USERLAND_SHARE_NSFD ioctl Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 15/26] exit: Support P_USERLAND in waitid() Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 16/26] signal: Support userland fds in pidfd_send_signal() Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 17/26] fork: Support CLONE_INTO_USERLAND in clone3() Jarkko Sakkinen
2026-11-22 20:28 ` bot+bpf-ci
2026-11-22 19:35 ` [RFC PATCH v7 18/26] fs: Support FSCONFIG_SET_USERLAND in fsconfig() Jarkko Sakkinen
2026-11-22 20:28 ` bot+bpf-ci
2026-11-22 19:35 ` [RFC PATCH v7 19/26] proc: Implement ->set_userland() fs_context operation Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 20/26] ipc/mqueue: " Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 21/26] security: Add userland LSM hooks Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 22/26] bpf: Register " Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 23/26] arch: Wire up userland_open() system call Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 24/26] docs: Document userland uAPI Jarkko Sakkinen
2026-11-22 20:09 ` bot+bpf-ci
2026-11-22 19:35 ` [RFC PATCH v7 25/26] selftests/userland: Add userland test suite Jarkko Sakkinen
2026-11-22 20:28 ` bot+bpf-ci [this message]
2026-11-22 19:35 ` [RFC PATCH v7 26/26] MAINTAINERS: Add entry for USERLAND Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ceb256f2afc7fa8c469f5f235f1e77aed593945868918788bc32ad76dee810ae@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=aleksa@amutable.com \
--cc=alex@amutable.com \
--cc=andrii@kernel.org \
--cc=arnd@arndb.de \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=containers@lists.linux.dev \
--cc=corbet@lwn.net \
--cc=daniel@iogearbox.net \
--cc=dhowells@redhat.com \
--cc=ebiggers@kernel.org \
--cc=eddyz87@gmail.com \
--cc=giuseppe@scrivano.org \
--cc=hughd@google.com \
--cc=ihor.solodrai@linux.dev \
--cc=jack@suse.cz \
--cc=jarkko@kernel.org \
--cc=jlayton@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kees@kernel.org \
--cc=kpsingh@kernel.org \
--cc=lennart@poettering.net \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-security-module@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=martin.lau@kernel.org \
--cc=mason@kernel.org \
--cc=neal@gompa.dev \
--cc=oleg@redhat.com \
--cc=paul@paul-moore.com \
--cc=ptikhomirov@virtuozzo.com \
--cc=sergeh@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=viro@zeniv.linux.org.uk \
--cc=yonghong.song@linux.dev \
--cc=zygmunt.krynicki@canonical.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®