]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
selftests/filesystems: test O_TMPFILE creation on idmapped mounts
authorChristian Brauner <brauner@kernel.org>
Mon, 15 Jun 2026 12:52:19 +0000 (14:52 +0200)
committerChristian Brauner <brauner@kernel.org>
Wed, 1 Jul 2026 13:26:18 +0000 (15:26 +0200)
commitd943e68edc5cb98192d38e31373bb6b6a73230c6
tree1b99c3fe47d2c61bf849abe31d561fa39ad3b62e
parent539dce1144651f7976fa418e618b0b574bf15eeb
selftests/filesystems: test O_TMPFILE creation on idmapped mounts

Add a regression test for the fsuidgid_has_mapping() check in
vfs_tmpfile().  It idmaps a detached tmpfs mount so that the
caller-visible id range [0, 10000) maps onto the on-disk range
[10000, 20000) and checks that:

  - a caller whose fsuid/fsgid fall outside that range cannot create an
    O_TMPFILE through the mount and gets -EOVERFLOW instead of an inode
    owned by (uid_t)-1;

  - a mapped caller can create an O_TMPFILE, link it into the namespace,
    and the ownership round-trips through the mount idmap: it is reported
    as 0 through the mount and stored as 10000 on the underlying tmpfs.

The test runs entirely as root and uses setfsuid()/setfsgid() to become
the unmapped caller, so it needs no helper user.  The layer directory is
world-writable so that an unmapped caller still clears the directory
permission check and reaches the fsuidgid_has_mapping() test.

Link: https://patch.msgid.link/20260615-work-idmapped-tmpfile-v1-2-754a94d81f83@kernel.org
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
tools/testing/selftests/filesystems/.gitignore
tools/testing/selftests/filesystems/Makefile
tools/testing/selftests/filesystems/idmapped_tmpfile.c [new file with mode: 0644]