[PATCH] selftests/filesystems: own the idmapped_tmpfile directory by a mapped id
From: Danish Khateeb
Date: Fri Sep 25 2026 - 16:15:10 EST
The idmapped_tmpfile fixture creates the test directory as root and makes
it world-writable, but the test mount only maps on-disk ids
[10000, 20000), so the directory's owner has no mapping in it.
inode_permission() refuses MAY_WRITE on such an inode with -EACCES
(HAS_UNMAPPED_ID()), whatever its mode. So:
- mapped_caller_creates_and_links has failed since it was added:
idmapped_tmpfile.c:145:mapped_caller_creates_and_links:Expected fd (-1) >= 0 (0)
- unmapped_caller_is_refused doesn't test what it describes. Without the
fsuidgid_has_mapping() check in vfs_tmpfile(), the unmapped caller is
still refused, with -EACCES from inode_permission(), instead of getting
a tmpfile owned by (uid_t)-1. The test only fails on the errno.
Give the directory a mapped owner, so that both callers pass the
permission check and only the idmapping decides.
Fixes: d943e68edc5c ("selftests/filesystems: test O_TMPFILE creation on idmapped mounts")
Assisted-by: LLM
Signed-off-by: Danish Khateeb <danishkhateeb03@xxxxxxxxx>
---
Notes:
Tested in QEMU x86_64 (KASAN/lockdep debug config) on next-20260925,
whose copy of the test is identical to mainline (v7.3-rc4-446):
- as is: unmapped_caller_is_refused passes,
mapped_caller_creates_and_links fails (openat() -> EACCES)
- with this patch: both pass
- with 539dce114465 ("fs: refuse O_TMPFILE creation with an unmapped
fsuid or fsgid") reverted: the original test fails only on the errno
(EACCES instead of EOVERFLOW), the patched one fails because the
unmapped caller gets a tmpfile
tools/testing/selftests/filesystems/idmapped_tmpfile.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/testing/selftests/filesystems/idmapped_tmpfile.c b/tools/testing/selftests/filesystems/idmapped_tmpfile.c
index bc411ab8281e..5968ac1cd04e 100644
--- a/tools/testing/selftests/filesystems/idmapped_tmpfile.c
+++ b/tools/testing/selftests/filesystems/idmapped_tmpfile.c
@@ -91,6 +91,11 @@ FIXTURE_SETUP(idmapped_tmpfile)
ASSERT_EQ(mkdir(self->dir, 0777), 0);
/* World-writable so an unmapped caller still passes permission(). */
ASSERT_EQ(chmod(self->dir, 0777), 0);
+ /*
+ * Owned by a mapped id, as inode_permission() refuses writes to an
+ * inode whose owner has no mapping in the mount.
+ */
+ ASSERT_EQ(chown(self->dir, MAP_HOST, MAP_HOST), 0);
}
FIXTURE_TEARDOWN(idmapped_tmpfile)
base-commit: aa98230e410f0ed212b6788c46b1e4d49e0ff7ca
--
2.55.0