Re: [RFC PATCH v10 19/28] fs: Support FSCONFIG_SET_RUN in fsconfig()

From: bot+bpf-ci

Date: Fri Dec 04 2026 - 23:18:22 EST


> fs: Support FSCONFIG_SET_RUN in fsconfig()

TL;DR:
- devpts ptmx may be owned by an unmapped host uid for run-bound mounts,
possibly making /dev/pts/ptmx unusable in the run
- FS_RUN_MOUNT comment omits that it allows fsopen() by callers failing
may_mount()

> diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
> index bd1e8eb26edb..814eed794da7 100644
> --- a/fs/devpts/inode.c
> +++ b/fs/devpts/inode.c

[ ... ]

> @@ -457,7 +463,7 @@ static struct file_system_type devpts_fs_type = {
> .init_fs_context = devpts_init_fs_context,
> .parameters = devpts_param_specs,
> .kill_sb = devpts_kill_sb,
> - .fs_flags = FS_USERNS_MOUNT,
> + .fs_flags = FS_USERNS_MOUNT | FS_RUN_MOUNT,
> };

With FS_RUN_MOUNT set here, a manager outside the run's user namespace can
now reach devpts_fill_super() and mknod_ptmx() for a run-bound context:

fsconfig(FSCONFIG_SET_RUN)
fsconfig(FSCONFIG_CMD_CREATE)
vfs_get_tree()
devpts_get_tree()
get_tree_nodev()
devpts_fill_super()
mknod_ptmx()

In mknod_ptmx() the owner of the ptmx inode comes from the current task:

kuid_t ptmx_uid = current_fsuid();
kgid_t ptmx_gid = current_fsgid();
...
inode->i_uid = ptmx_uid;
inode->i_gid = ptmx_gid;

Here current is the manager, not a task inside fc->user_ns. If the manager
is host root (kuid 0) and the run maps 0..65535 to 100000..165535, the ptmx
node of a superblock with s_user_ns set to the run's user namespace ends up
owned by kuid 0 / kgid 0, which is not mapped in s_user_ns.

With the default DEVPTS_DEFAULT_PTMX_MODE (0000), can any task in the run
still open /dev/pts/ptmx? generic_permission() denies by mode, and
capable_wrt_inode_uidgid(CAP_DAC_OVERRIDE) should fail because
privileged_wrt_inode_uidgid() requires the inode uid/gid to be mapped in the
caller's namespace. chmod looks like it fails the same way, since
inode_owner_or_capable() needs the mapping for CAP_FOWNER. Only a remount
with ptmxmode= appears to recover it.

This also seems inconsistent with the kuid_has_mapping(fc->user_ns, ...) and
kgid_has_mapping(fc->user_ns, ...) checks this patch adds to
devpts_parse_param(), which keep explicit uid=/gid= options from giving the
instance an owner that is unmapped in fc->user_ns. The implicit owner taken
from current is neither checked nor remapped.

The commit message says fc->cred is refreshed for the run binding, but
mknod_ptmx() does not use fc->cred.

Should the owner be derived from fc->user_ns when fc->run_bound is set, for
example make_kuid(fc->user_ns, 0) and make_kgid(fc->user_ns, 0), or should
an unmapped owner be rejected?

[ ... ]

> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 5b3a100aba77..91479495b49e 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2306,6 +2306,7 @@ struct file_system_type {
> #define FS_USERNS_MOUNT_RESTRICTED 512 /* Restrict mount in userns if not already visible */
> #define FS_USERNS_DELEGATABLE 1024 /* Can be mounted inside userns from outside */
> #define FS_DISALLOW_NOTIFY 2048 /* No fsnotify marks on its objects */
> +#define FS_RUN_MOUNT 4096 /* Supports FSCONFIG_SET_RUN */
> #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */

Does this comment describe the whole effect of the flag? In sys_fsopen() it
is what lets a caller that fails may_mount() open the filesystem at all:

priv = may_mount();
if (!priv && !IS_ENABLED(CONFIG_RUNFD))
return -EPERM;
...
if (!priv && !(fs_type->fs_flags & FS_RUN_MOUNT)) {
put_filesystem(fs_type);
return -EPERM;
}

The flag is also not required for FSCONFIG_SET_RUN itself, since
fsconfig_set_run() accepts either flag:

if (!(fc->fs_type->fs_flags &
(FS_RUN_MOUNT | FS_USERNS_DELEGATABLE)))
return -EOPNOTSUPP;

A filesystem with only FS_USERNS_DELEGATABLE (bpf, nfs, nfs4) therefore
supports FSCONFIG_SET_RUN without FS_RUN_MOUNT, while a filesystem that sets
FS_RUN_MOUNT because it "supports FSCONFIG_SET_RUN" also lets any user
fsopen() it when CONFIG_RUNFD=y.

Could the comment (and the new mount_api.rst text) say that FS_RUN_MOUNT
permits fsopen() by callers that fail may_mount()?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47474652355