mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Danish Khateeb <danishkhateeb03@gmail.com>
To: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>, Shuah Khan <shuah@kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Danish Khateeb <danishkhateeb03@gmail.com>
Subject: [PATCH] selftests/filesystems: own the idmapped_tmpfile directory by a mapped id
Date: Fri, 25 Sep 2026 15:14:41 -0500	[thread overview]
Message-ID: <20260925201441.105313-1-danishkhateeb03@gmail.com> (raw)

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


                 reply	other threads:[~2026-09-25 20:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260925201441.105313-1-danishkhateeb03@gmail.com \
    --to=danishkhateeb03@gmail.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®