The recent idmapped_tmpfile selftest creates a new directory in tmpfs
owned by user ID 0. It then idmaps the mount as caller [0,10000) to disk
[10000,20000). The original uid 0 owner does not exist in the mapped
range. As a result, mapped_caller_creates_and_links fails at the
O_TMPFILE open because inode_permission() rejects MAY_WRITE access:

  idmapped_tmpfile.c:145:mapped_caller_creates_and_links:
  Expected fd (-1) >= 0 (0)

Chown the directory into the mapped range to satisfy the UID
requirement.

Fixes: d943e68edc5cb ("selftests/filesystems: test O_TMPFILE creation on 
idmapped mounts")
Cc: [email protected] # 7.2+
Assisted-by: kiro:claude-opus-5
Signed-off-by: Bjoern Doebel <[email protected]>
---
 tools/testing/selftests/filesystems/idmapped_tmpfile.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/filesystems/idmapped_tmpfile.c 
b/tools/testing/selftests/filesystems/idmapped_tmpfile.c
index bc411ab8281ea..77b96d0943578 100644
--- a/tools/testing/selftests/filesystems/idmapped_tmpfile.c
+++ b/tools/testing/selftests/filesystems/idmapped_tmpfile.c
@@ -91,6 +91,13 @@ 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);
+       /*
+        * The directory itself must be inside the range the mount maps.
+        * Left owned by 0 it has no mapping in the mount, and
+        * inode_permission() then fails MAY_WRITE via HAS_UNMAPPED_ID()
+        * before any of the tmpfile logic is reached, regardless of mode.
+        */
+       ASSERT_EQ(chown(self->dir, MAP_HOST, MAP_HOST), 0);
 }
 
 FIXTURE_TEARDOWN(idmapped_tmpfile)
-- 
2.50.1


Reply via email to