]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
selftests/filesystems: add tests for empty mount namespaces
authorChristian Brauner <brauner@kernel.org>
Fri, 6 Mar 2026 16:28:38 +0000 (17:28 +0100)
committerChristian Brauner <brauner@kernel.org>
Thu, 12 Mar 2026 12:33:55 +0000 (13:33 +0100)
commit32f54f2bbccfdeff81d930d18ccf3161a1c203b9
tree5d5b20a867f2bd79d650b3629106a5fa281bc866
parent9d4e752a24f740b31ca827bfab07010e4e7f34b0
selftests/filesystems: add tests for empty mount namespaces

Add a test suite for the UNSHARE_EMPTY_MNTNS and CLONE_EMPTY_MNTNS
flags exercising the empty mount namespace functionality through the
kselftest harness.

The tests cover:

- basic functionality: unshare succeeds, exactly one mount exists in
  the new namespace, root and cwd point to the same mount
- flag interactions: UNSHARE_EMPTY_MNTNS works standalone without
  explicit CLONE_NEWNS, combines correctly with CLONE_NEWUSER and
  other namespace flags (CLONE_NEWUTS, CLONE_NEWIPC)
- edge cases: EPERM without capabilities, works from a user namespace,
  many source mounts still result in one mount, cwd on a different
  mount gets reset to root
- error paths: invalid flags return EINVAL
- regression: plain CLONE_NEWNS still copies the full mount tree,
  other namespace unshares are unaffected
- mount properties: the root mount has the expected statmount
  properties, is its own parent, and is the only entry returned by
  listmount
- repeated unshare: consecutive UNSHARE_EMPTY_MNTNS calls each
  produce a new namespace with a distinct mount ID
- overmount workflow: verifies the intended usage pattern of creating
  an empty mount namespace with a nullfs root and then mounting tmpfs
  over it to build a writable filesystem from scratch

Link: https://patch.msgid.link/20260306-work-empty-mntns-consolidated-v1-2-6eb30529bbb0@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
tools/testing/selftests/filesystems/empty_mntns/.gitignore [new file with mode: 0644]
tools/testing/selftests/filesystems/empty_mntns/Makefile [new file with mode: 0644]
tools/testing/selftests/filesystems/empty_mntns/empty_mntns.h [new file with mode: 0644]
tools/testing/selftests/filesystems/empty_mntns/empty_mntns_test.c [new file with mode: 0644]
tools/testing/selftests/filesystems/empty_mntns/overmount_chroot_test.c [new file with mode: 0644]
tools/testing/selftests/filesystems/utils.c
tools/testing/selftests/filesystems/utils.h