Skip to contentSkip to conversation

selftests/filesystems: Fix idmapped_tmpfile layer dir ownership

PATCH Applied Bjoern Doebel 2 participants 2 messages Oct 1 – Oct 12

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/filesystems: Fix idmapped_tmpfile layer dir ownership

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")
Assisted-by kiro:claude-opus-5
---
 tools/testing/selftests/filesystems/idmapped_tmpfile.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/testing/selftests/filesystems/idmapped_tmpfile.c +7 -0
index bc411ab8281ea..77b96d0943578 100644
@@ -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)
Signature · 1 line
2.50.1
#1 lore raw
Quoted 10 lines · Bjoern Doebel

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)

[...]

Applied to the vfs-7.4.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.4.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.4.misc

[1/1] selftests/filesystems: Fix idmapped_tmpfile layer dir ownership

      https://git.kernel.org/vfs/vfs/c/9ba6627ef6b1