fs: refuse O_TMPFILE creation with an unmapped fsuid or fsgid
Get series with b4
b4 am [email protected] change-id 20260615-work-idmapped-tmpfile-6b522f9db9a2Versions newest first
- v1 Latest2 patches 8 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | fs: refuse O_TMPFILE creation with an unmapped fsuid or fsgidfs/ | +4 | 7 replies | |
| 2/2 | selftests/filesystems: test O_TMPFILE creation on idmapped mountstools/ tools/ tools/ | +173 | 1 reply |
Reviews trailers per patch
All 2 patches have a Reviewed-by or Acked-by.
| Patch | Jan Kara |
|---|---|
| 1/2 | R-b |
| 2/2 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 0/2] fs: refuse O_TMPFILE creation with an unmapped fsuid or fsgid
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.
---
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