Linux filesystem development
 help / color / mirror / Atom feed
* [PATCH 0/2] fs: refuse O_TMPFILE creation with an unmapped fsuid or fsgid
@ 2026-06-15 12:52 Christian Brauner
  2026-06-15 12:52 ` [PATCH 1/2] " Christian Brauner
  2026-06-15 12:52 ` [PATCH 2/2] selftests/filesystems: test O_TMPFILE creation on idmapped mounts Christian Brauner
  0 siblings, 2 replies; 11+ messages in thread
From: Christian Brauner @ 2026-06-15 12:52 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Alexander Viro, Jan Kara, Christian Brauner (Amutable)

vfs_tmpfile() is the only object-creation path in the VFS that never
checked whether the caller's fsuid and fsgid map into the filesystem.

On an idmapped mount whose idmapping does not cover the caller's
fs{u,g}id, the ->tmpfile() instance initializes the new inode through
inode_init_owner(), where mapped_fsuid()/mapped_fsgid() return
INVALID_UID/INVALID_GID.  The tmpfile ends up owned by (uid_t)-1, and
because it is created I_LINKABLE it can subsequently be spliced into the
namespace with linkat(2).

Every other creation path already refuses this: may_o_create() (O_CREAT)
and may_create_dentry() (mkdir, mknod, symlink, link) bail out with
-EOVERFLOW via fsuidgid_has_mapping() precisely so that an object cannot
be created with an owner the filesystem cannot represent.  O_TMPFILE is
no exception and must hold the same guarantee.

Patch 1 adds the missing fsuidgid_has_mapping() check to vfs_tmpfile().
It is a no-op on non-idmapped mounts -- there the caller's fs{u,g}id
always map in the superblock's user namespace -- and only takes effect
on an idmapped mount that does not map the caller.  It applies to every
filesystem that sets FS_ALLOW_IDMAP and implements ->tmpfile() (tmpfs,
ext4, btrfs, xfs, f2fs, ...), and to overlayfs, whose upper-layer
tmpfile creation funnels through vfs_tmpfile() via
backing_tmpfile_open().

Patch 2 adds a selftest that idmaps a detached tmpfs mount and checks
both directions: an unmapped caller is refused with -EOVERFLOW, while a
mapped caller can create an O_TMPFILE, link it into the namespace, and
have its ownership round-trip through the mount idmap.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
Christian Brauner (2):
      fs: refuse O_TMPFILE creation with an unmapped fsuid or fsgid
      selftests/filesystems: test O_TMPFILE creation on idmapped mounts

 fs/namei.c                                         |   4 +
 tools/testing/selftests/filesystems/.gitignore     |   1 +
 tools/testing/selftests/filesystems/Makefile       |   4 +
 .../selftests/filesystems/idmapped_tmpfile.c       | 168 +++++++++++++++++++++
 4 files changed, 177 insertions(+)
---
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
change-id: 20260615-work-idmapped-tmpfile-6b522f9db9a2


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-07-10  5:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-15 12:52 [PATCH 0/2] fs: refuse O_TMPFILE creation with an unmapped fsuid or fsgid Christian Brauner
2026-06-15 12:52 ` [PATCH 1/2] " Christian Brauner
2026-06-15 13:29   ` Jan Kara
2026-07-04 11:31   ` Christoph Hellwig
2026-07-07  2:18     ` Darrick J. Wong
2026-07-07  7:20       ` Christian Brauner
2026-07-07 11:20         ` Christian Brauner
2026-07-07 16:47           ` Darrick J. Wong
2026-07-10  5:31           ` Christoph Hellwig
2026-06-15 12:52 ` [PATCH 2/2] selftests/filesystems: test O_TMPFILE creation on idmapped mounts Christian Brauner
2026-06-15 13:33   ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox