Re: [RFC PATCH v6 18/26] fs: Support FSCONFIG_SET_USERLAND in fsconfig()
From: bot+bpf-ci
Date: Sat Nov 21 2026 - 21:14:31 EST
> fs: Support FSCONFIG_SET_USERLAND in fsconfig()
TL;DR:
- fsmount() may call may_mount() needlessly for userland-bound contexts,
possibly causing spurious LSM denial logs and BPF-LSM hooks
- mount_api.rst may need updating for ->set_userland()
> diff --git a/fs/namespace.c b/fs/namespace.c
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
[ ... ]
> @@ -4705,16 +4705,19 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
> struct vfsmount *new_mnt;
> struct mount *mnt;
> unsigned int mnt_flags = 0;
> + bool priv;
> long ret;
>
> if ((flags & ~(FSMOUNT_CLOEXEC | FSMOUNT_NAMESPACE)) != 0)
> return -EINVAL;
>
> + priv = may_mount();
> if ((flags & FSMOUNT_NAMESPACE) &&
> !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
> return -EPERM;
Previously may_mount() was only called when FSMOUNT_NAMESPACE was clear.
Now it runs on every fsmount() call, but priv is only read later in:
} else if (!(flags & FSMOUNT_NAMESPACE) && !priv) {
so the result is discarded for FSMOUNT_NAMESPACE callers and for every
userland-bound context.
may_mount() is an audited ns_capable() that goes through security_capable()
and sets PF_SUPERPRIV on success. Can an external manager under an LSM
policy that denies capability sys_admin but allows the user namespace check
now trigger an LSM denial log entry and BPF-LSM capable programs on each
userland-bound fsmount(), for a privilege the call does not need?
The other conditional callers in this file only evaluate it when the result
matters:
if ((flags & OPEN_TREE_CLONE) && !may_mount())
if (!(flags & MOVE_MOUNT_T_MNTNS) && !may_mount())
Could may_mount() be called only on the unbound, non-FSMOUNT_NAMESPACE path
once fc->userland_bound is known?
[ ... ]
> diff --git a/include/linux/fs_context.h b/include/linux/fs_context.h
> --- a/include/linux/fs_context.h
> +++ b/include/linux/fs_context.h
[ ... ]
> struct fs_context_operations {
> @@ -117,6 +122,7 @@ struct fs_context_operations {
> int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
> int (*parse_param)(struct fs_context *fc, struct fs_parameter *param);
> int (*parse_monolithic)(struct fs_context *fc, void *data);
> + int (*set_userland)(struct fs_context *fc, struct userland *userland);
> int (*get_tree)(struct fs_context *fc);
> int (*reconfigure)(struct fs_context *fc);
> };
Documentation/filesystems/mount_api.rst keeps its own copy of struct
fs_context_operations and documents each method. Should it be updated for
->set_userland(), the new userland_bound and userland_mnt_id fields and the
new fs_context_phase states?
Filesystem implementers currently have to read fsconfig_set_userland() in
fs/fsopen.c to learn the contract:
- it is called after ->init_fs_context() has run with fc->user_ns,
fc->net_ns and fc->cred already rebound;
- it may rebind fc->user_ns, but must leave it equal to the userland's user
namespace, or the bind fails with -EOPNOTSUPP;
- the context moves to FS_CONTEXT_FAILED on error.
---
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/44972669664