* [PATCH] selftests/filesystems: own the idmapped_tmpfile directory by a mapped id
@ 2026-09-25 20:14 Danish Khateeb
0 siblings, 0 replies; only message in thread
From: Danish Khateeb @ 2026-09-25 20:14 UTC (permalink / raw)
To: Christian Brauner
Cc: Jan Kara, Shuah Khan, linux-fsdevel, linux-kselftest,
linux-kernel, Danish Khateeb
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@gmail.com>
---
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-25 20:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-25 20:14 [PATCH] selftests/filesystems: own the idmapped_tmpfile directory by a mapped id Danish Khateeb
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®