linux/fs/overlayfs
Christian Brauner 63981fc786
ovl: don't warn when the mount is completed from another user namespace
fsopen() records the caller's user namespace in fc->user_ns and hands
back an ordinary file descriptor. Nothing ties the task that calls
fsconfig(FSCONFIG_CMD_CREATE) to the task that created the context. The
fd is inherited across fork() and exec() and it can be passed over a
unix socket.

Completing a context from another user namespace is allowed on purpose.
vfs_cmd_create() authorizes the create with mount_capable(), which for
FS_USERNS_MOUNT checks ns_capable(fc->user_ns, CAP_SYS_ADMIN), and that
succeeds for a task holding CAP_SYS_ADMIN in an ancestor of fc->user_ns.
So an unprivileged task can reach the WARN_ON() in ovl_fill_super():
create a user and a mount namespace in a child, call fsopen("overlay")
there, send the fscontext fd to the parent and let the parent issue
FSCONFIG_CMD_CREATE. Both namespaces come from a plain unshare(1) and no
capability is needed anywhere:

  WARNING: fs/overlayfs/super.c:1551 at ovl_fill_super+0x7b9/0x1e20 [overlay]
  CPU: 3 UID: 1000 PID: 3243376 Comm: fswarn
  Call Trace:
   get_tree_nodev+0x71/0xa0
   ovl_get_tree+0x15/0x20 [overlay]
   vfs_get_tree+0x2a/0x100
   vfs_cmd_create+0x60/0xf0
   __do_sys_fsconfig+0x4b2/0x500

The child needs the mount namespace because fsopen() itself gates on
may_mount(), which asks for CAP_SYS_ADMIN in the user namespace owning
the caller's mount namespace. fsconfig() doesn't repeat that check.

It is a WARN_ON() and not a WARN_ON_ONCE(), so the condition can be
raised in a loop to taint the kernel and flood the log, and it panics a
kernel booted with panic_on_warn.

Keep refusing the mount and stop warning about it. ovl_parse_param()
already spells a user namespace check this way for Opt_override_creds.

Fixes: 1784fbc2ed ("ovl: port to new mount api")
Cc: stable@vger.kernel.org # v6.5+
Link: https://patch.msgid.link/20260802-work-fill_super-warn-v1-1-4e987911a39a@kernel.org
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-08-10 09:35:54 +02:00
..
copy_up.c ovl: use linked upper dentry in copy-up tmpfile 2026-07-01 15:26:24 +02:00
dir.c Fixing livelocks in shrink_dcache_tree() 2026-04-21 07:30:44 -07:00
export.c vfs-7.1-rc1.kino 2026-04-13 12:19:01 -07:00
file.c ovl: check access to copy_file_range source with src mounter creds 2026-07-22 16:42:28 +02:00
inode.c ovl: fix comment about locking order 2026-07-01 15:26:25 +02:00
Kconfig fs: prepare for stackable filesystems backing file helpers 2023-12-23 16:35:08 +02:00
Makefile ovl: Move xattr support to new xattrs.c file 2023-10-31 00:12:59 +02:00
namei.c treewide: change inode->i_ino from unsigned long to u64 2026-03-06 14:31:28 +01:00
overlayfs.h vfs-7.1-rc1.directory 2026-04-13 10:24:33 -07:00
ovl_entry.h ovl: make fsync after metadata copy-up opt-in mount option 2026-03-27 12:48:10 +01:00
params.c ovl: make fsync after metadata copy-up opt-in mount option 2026-03-27 12:48:10 +01:00
params.h ovl: Prepare for mounting case-insensitive enabled layers 2025-09-23 12:29:35 +02:00
readdir.c ovl: keep err zero after successful ovl_cache_get() 2026-05-18 14:56:15 +02:00
super.c ovl: don't warn when the mount is completed from another user namespace 2026-08-10 09:35:54 +02:00
util.c ovl: fix verity lazy-load guard broken by fsverity_active() semantic change 2026-05-06 08:37:30 -07:00
xattrs.c ovl: fix trusted xattr escape prefix matching 2026-07-22 13:48:00 +02:00