[RFC PATCH v6 25/26] selftests/userland: Add userland test suite

sashiko-bot at kernel.org sashiko-bot at kernel.org
Sun Nov 22 01:39:09 UTC 2026


Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] selftests/userland: host /tmp mount leak in
  check_child_src_slave_locking()
- [Medium] selftests/userland: 64K-page E2BIG failure in
  test_userns_set_idmap()
- [Low] selftests/userland: Python 3.10+ parenthesized with-statements
  in test
--

commit ceac0bb92c4f38107df4d9a282065b54c6373344
Author: Jarkko Sakkinen <jarkko at kernel.org>

selftests/userland: Add userland test suite

This commit adds a kselftest suite for the userland control object uAPI,
covering namespace sharing, mount-namespace configuration, waitid(P_USERLAND),
pidfd_send_signal(), and userns_set_idmap().

> diff --git a/tools/testing/selftests/userland/userland_test.py b/tools/testing/selftests/userland/userland_test.py
> new file mode 100755
> index 0000000000000..eb29cbc9c8f10
> --- /dev/null
> +++ b/tools/testing/selftests/userland/userland_test.py
> @@ -0,0 +1,2306 @@

[ ... ]

> +            with (
> +                self.closing_fd(rns.get_nsfd(CloneFlag.NEWNS)) as mntns_fd,
> +                self.closing_fd(rns.make_mount("tmpfs")) as rootfd,
> +            ):

[Severity: Low]
Will parenthesized multi-item with-statements fail with a SyntaxError on
Python 3.9?

Documentation/process/changes.rst specifies Python 3.9.x as the minimal
supported version, whereas parenthesized context managers across multiple
clauses were added in Python 3.10.

[ ... ]

> +            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,
> +                    )

[Severity: Medium]
When running as root, does check_child_src_slave_locking() propagate its
tmpfs mount onto the host /tmp and leave it mounted after the test exits?

enter_userns_if_unpriv() is a no-op when os.geteuid() == 0, so
os.unshare(CloneFlag.NEWNS) stays in the initial user namespace and
preserves MS_SHARED peer groups with the host mount namespace.  Mounting
tfd onto /tmp without first calling Sys.set_mount_propagation("/") (as
check_standalone_mntns() does) propagates a fresh tmpfs over the host
/tmp, and cleanup only detaches /tmp/sub.

[ ... ]

> +            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)

[Severity: Medium]
Does this assertion fail on kernels with 64 KiB (or larger) base pages?

userns_set_idmap() returns -E2BIG only when size > PAGE_SIZE.  On a 64 KiB
page kernel, size=65536 passes the PAGE_SIZE check, copy_struct_from_user()
succeeds on the zero-filled buffer, and the syscall returns -EINVAL instead
because the extent counts are all zero.  Sizing the buffer with
os.sysconf("SC_PAGE_SIZE") + 1 would exceed PAGE_SIZE on all architectures.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122011809.2667684-1-jarkko@kernel.org?part=25



More information about the Linux-security-module-archive mailing list