From: Jarkko Sakkinen <jarkko@kernel.org>
To: fsdevel@vger.kernel.org
Cc: "Jarkko Sakkinen" <jarkko@kernel.org>,
bpf@vger.kernel.org, containers@lists.linux.dev,
linux-api@vger.kernel.org, linux-arch@vger.kernel.org,
linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-mm@kvack.org,
linux-security-module@vger.kernel.org,
"Aleksa Sarai" <aleksa@amutable.com>,
"Alexander Mikhalitsyn" <alex@amutable.com>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Alexei Starovoitov" <ast@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Andy Lutomirski" <luto@amacapital.net>,
"Arnd Bergmann" <arnd@arndb.de>,
"Baolin Wang" <baolin.wang@linux.alibaba.com>,
"Ben Segall" <bsegall@google.com>,
"Christian Brauner" <brauner@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"David Hildenbrand" <david@kernel.org>,
"David Howells" <dhowells@redhat.com>,
"David Woodhouse" <dwmw2@infradead.org>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Emil Tsalapatis" <emil@etsalapatis.com>,
"Eric Biggers" <ebiggers@kernel.org>,
"Georgia Garcia" <georgia.garcia@canonical.com>,
"Giuseppe Scrivano" <giuseppe@scrivano.org>,
"Günther Noack" <gnoack@google.com>,
"Hugh Dickins" <hughd@google.com>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>,
"Ingo Molnar" <mingo@redhat.com>,
"James Morris" <jmorris@namei.org>, "Jan Kara" <jack@suse.cz>,
"Jason Gunthorpe" <jgg@nvidia.com>,
"Jeff Layton" <jlayton@kernel.org>,
"Jiri Olsa" <jolsa@kernel.org>,
"John Johansen" <john.johansen@canonical.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Josef Bacik" <josef@toxicpanda.com>,
"Juri Lelli" <juri.lelli@redhat.com>,
"Kees Cook" <kees@kernel.org>,
"K Prateek Nayak" <kprateek.nayak@amd.com>,
"KP Singh" <kpsingh@kernel.org>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Lennart Poettering" <lennart@poettering.net>,
"Liam R. Howlett" <liam@infradead.org>,
"Manfred Spraul" <manfred@colorfullife.com>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Matt Bobrowski" <matt@bobrowski.net>,
"Mel Gorman" <mgorman@suse.de>, "Michal Hocko" <mhocko@suse.com>,
"Mickaël Salaün" <mic@digikod.net>,
"Mike Rapoport" <rppt@kernel.org>, "Neal Gompa" <neal@gompa.dev>,
"Oleg Nesterov" <oleg@redhat.com>,
"Paul Moore" <paul@paul-moore.com>,
"Pavel Tikhomirov" <ptikhomirov@virtuozzo.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
"Serge Hallyn" <sergeh@kernel.org>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Song Liu" <song@kernel.org>,
"Stephen Smalley" <stephen.smalley.work@gmail.com>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Valentin Schneider" <vschneid@redhat.com>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Zygmunt Krynicki" <zygmunt.krynicki@canonical.com>
Subject: [RFC PATCH v10 05/28] mount: Support MOVE_MOUNT_T_MNTNS in move_mount()
Date: Sat, 5 Dec 2026 05:26:10 +0200 [thread overview]
Message-ID: <20261205032633.1702772-6-jarkko@kernel.org> (raw)
In-Reply-To: <20261205032633.1702772-1-jarkko@kernel.org>
move_mount() currently resolves target paths only against the caller's
filesystem view or anonymous mount fds, preventing an external manager
from populating an empty mount namespace or hot-mounting into an
existing container's mount namespace without entering it first.
Add MOVE_MOUNT_T_MNTNS to attach detached anonymous mount trees into a
target mount namespace nsfs file descriptor. Installing "/" attaches the
initial root mount onto the nullfs root of an empty mount namespace at
most once, while relative target paths resolve with LOOKUP_IN_ROOT
beneath the live mount namespace root and reject root-mount aliases
under namespace_lock().
Check CAP_SYS_ADMIN in the target mount namespace's owning user
namespace instead of caller may_mount(), check nsfs mount loops against
the destination mount namespace, and lock moved mount trees inside
attach_recursive_mnt() when crossing user namespace boundaries.
Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
fs/namespace.c | 245 ++++++++++++++++++++++++++++++-------
fs/pnode.c | 39 +++++-
fs/pnode.h | 3 +-
include/uapi/linux/mount.h | 3 +-
4 files changed, 244 insertions(+), 46 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index 1bb9f90a6523..45a7f9547c8e 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2202,7 +2202,8 @@ struct mnt_namespace *mnt_ns_from_dentry(struct dentry *dentry)
return to_mnt_ns(get_proc_ns(dentry->d_inode));
}
-static bool mnt_ns_loop(struct dentry *dentry)
+static bool mnt_ns_loop_target(struct dentry *dentry,
+ struct mnt_namespace *target_mnt_ns)
{
/* Could bind mounting the mount namespace inode cause a
* mount namespace loop?
@@ -2212,7 +2213,12 @@ static bool mnt_ns_loop(struct dentry *dentry)
if (!mnt_ns)
return false;
- return current->nsproxy->mnt_ns->ns.ns_id >= mnt_ns->ns.ns_id;
+ return target_mnt_ns->ns.ns_id >= mnt_ns->ns.ns_id;
+}
+
+static bool mnt_ns_loop(struct dentry *dentry)
+{
+ return mnt_ns_loop_target(dentry, current->nsproxy->mnt_ns);
}
struct mount *copy_tree(struct mount *src_root, struct dentry *dentry,
@@ -2239,9 +2245,13 @@ struct mount *copy_tree(struct mount *src_root, struct dentry *dentry,
for (src_mnt = src_root_child; src_mnt;
src_mnt = next_mnt(src_mnt, src_root_child)) {
+ bool src_locked = (src_mnt->mnt.mnt_flags & MNT_LOCKED) ||
+ ((flag & CL_LOCK_SOURCE) &&
+ list_empty(&src_mnt->mnt_expire));
+
if (!(flag & CL_COPY_UNBINDABLE) &&
IS_MNT_UNBINDABLE(src_mnt)) {
- if (src_mnt->mnt.mnt_flags & MNT_LOCKED) {
+ if (src_locked) {
/* Both unbindable and locked. */
dst_mnt = ERR_PTR(-EPERM);
goto out;
@@ -2252,7 +2262,7 @@ struct mount *copy_tree(struct mount *src_root, struct dentry *dentry,
}
if (!(flag & CL_COPY_MNT_NS_FILE) &&
is_mnt_ns_file(src_mnt->mnt.mnt_root)) {
- if (src_mnt->mnt.mnt_flags & MNT_LOCKED) {
+ if (src_locked) {
/* Both a mount namespace file and locked. */
dst_mnt = ERR_PTR(-EPERM);
goto out;
@@ -2423,10 +2433,11 @@ static bool __has_children(struct mount *mnt, struct dentry *dentry)
*
* locks: mount_locked_reader || namespace_shared && pinned(subtree)
*/
-static bool check_for_nsfs_mounts(struct mount *subtree)
+static bool check_for_nsfs_mounts(struct mount *subtree,
+ struct mnt_namespace *target_mnt_ns)
{
for (struct mount *p = subtree; p; p = next_mnt(p, subtree))
- if (mnt_ns_loop(p->mnt.mnt_root))
+ if (mnt_ns_loop_target(p->mnt.mnt_root, target_mnt_ns))
return false;
return true;
}
@@ -2464,7 +2475,7 @@ struct vfsmount *clone_private_mount(const struct path *path)
if (!anon_ns_root(old_mnt))
return ERR_PTR(-EINVAL);
- if (!check_for_nsfs_mounts(old_mnt))
+ if (!check_for_nsfs_mounts(old_mnt, current->nsproxy->mnt_ns))
return ERR_PTR(-EINVAL);
}
@@ -2564,12 +2575,16 @@ int count_mounts(struct mnt_namespace *ns, struct mount *mnt)
enum mnt_tree_flags_t {
MNT_TREE_BENEATH = BIT(0),
MNT_TREE_PROPAGATION = BIT(1),
+ MNT_TREE_MNTNS = BIT(2),
+ MNT_TREE_MNTNS_INIT = BIT(3),
};
/**
* attach_recursive_mnt - attach a source mount tree
* @source_mnt: mount tree to be attached
* @dest: the context for mounting at the place where the tree should go
+ * @src_user_ns: owning user namespace of @source_mnt for MOVE_MOUNT_T_MNTNS,
+ * or NULL
*
* NOTE: in the table below explains the semantics when a source mount
* of a given type is attached to a destination mount of a given type.
@@ -2632,7 +2647,8 @@ enum mnt_tree_flags_t {
* Otherwise a negative error code is returned.
*/
static int attach_recursive_mnt(struct mount *source_mnt,
- const struct pinned_mountpoint *dest)
+ const struct pinned_mountpoint *dest,
+ struct user_namespace *src_user_ns)
{
struct mount *dest_mnt = dest->parent;
struct mountpoint *dest_mp = dest->mp;
@@ -2688,7 +2704,8 @@ static int attach_recursive_mnt(struct mount *source_mnt,
err = invent_group_ids(source_mnt, true);
if (err)
goto out;
- err = propagate_mnt(dest_mnt, dest_mp, source_mnt, &tree_list);
+ err = propagate_mnt(dest_mnt, dest_mp, source_mnt, &tree_list,
+ src_user_ns);
}
lock_mount_hash();
if (err)
@@ -2725,11 +2742,22 @@ static int attach_recursive_mnt(struct mount *source_mnt,
hlist_add_head(&source_mnt->mnt_hash, &tree_list);
hlist_for_each_entry_safe(child, n, &tree_list, mnt_hash) {
+ struct user_namespace *child_user_ns =
+ child->mnt_parent->mnt_ns->user_ns;
+ bool cross_child_src = src_user_ns &&
+ !in_userns(child_user_ns, src_user_ns);
struct mount *q;
+
hlist_del_init(&child->mnt_hash);
- /* Notice when we are propagating across user namespaces */
- if (child->mnt_parent->mnt_ns->user_ns != user_ns)
+ /*
+ * Notice when we are propagating or attaching a foreign
+ * source tree across user namespaces.
+ */
+ if (child_user_ns != user_ns || cross_child_src) {
lock_mnt_tree(child);
+ if (cross_child_src && list_empty(&child->mnt_expire))
+ child->mnt.mnt_flags |= MNT_LOCKED;
+ }
q = __lookup_mnt(&child->mnt_parent->mnt,
child->mnt_mountpoint);
commit_tree(child);
@@ -2937,7 +2965,7 @@ static int graft_tree(struct mount *mnt, const struct pinned_mountpoint *mp)
d_is_dir(mnt->mnt.mnt_root))
return -ENOTDIR;
- return attach_recursive_mnt(mnt, mp);
+ return attach_recursive_mnt(mnt, mp, NULL);
}
static int may_change_propagation(const struct mount *m)
@@ -3131,7 +3159,7 @@ static int do_loopback(const struct path *path, const char *old_name,
return PTR_ERR(mnt);
/* the copy may carry mount namespace files from below the source */
- if (recurse && !check_for_nsfs_mounts(mnt))
+ if (recurse && !check_for_nsfs_mounts(mnt, current->nsproxy->mnt_ns))
err = -EINVAL;
else
err = graft_tree(mnt, &mp);
@@ -3776,9 +3804,12 @@ static inline bool may_use_mount(struct mount *mnt)
static int do_move_mount(const struct path *old_path,
const struct path *new_path,
- enum mnt_tree_flags_t flags)
+ enum mnt_tree_flags_t flags,
+ struct mnt_namespace *target_mnt_ns)
{
struct mount *old = real_mount(old_path->mnt);
+ struct user_namespace *src_user_ns = NULL;
+ struct mnt_namespace *dest_mnt_ns;
int err;
bool beneath = flags & MNT_TREE_BENEATH;
@@ -3792,7 +3823,30 @@ static int do_move_mount(const struct path *old_path,
if (IS_ERR(mp.parent))
return PTR_ERR(mp.parent);
- if (check_mnt(old)) {
+ if (flags & MNT_TREE_MNTNS) {
+ u64 seq;
+
+ if (!anon_ns_root(old) || old->mnt_ns == mp.parent->mnt_ns ||
+ mp.parent->mnt_ns != target_mnt_ns)
+ return -EINVAL;
+ seq = old->mnt_ns->seq_origin;
+ if (seq && seq != target_mnt_ns->ns.ns_id &&
+ seq != current->nsproxy->mnt_ns->ns.ns_id)
+ return -EINVAL;
+ src_user_ns = old->mnt_ns->user_ns;
+ if (flags & MNT_TREE_MNTNS_INIT) {
+ if (mp.parent != target_mnt_ns->root)
+ return -EBUSY;
+ } else if (mp.mp->m_dentry == mp.parent->mnt.mnt_root) {
+ const struct mount *m = mp.parent;
+
+ while (m != target_mnt_ns->root && mnt_has_parent(m) &&
+ m->mnt_mountpoint == m->mnt_parent->mnt.mnt_root)
+ m = m->mnt_parent;
+ if (m == target_mnt_ns->root)
+ return beneath ? -EINVAL : -EBUSY;
+ }
+ } else if (check_mnt(old)) {
/* if the source is in our namespace... */
/* ... it should be detachable from parent */
if (!mnt_has_parent(old) || IS_MNT_LOCKED(old))
@@ -3840,12 +3894,14 @@ static int do_move_mount(const struct path *old_path,
*/
if (IS_MNT_SHARED(mp.parent) && tree_contains_unbindable(old))
return -EINVAL;
- if (!check_for_nsfs_mounts(old))
+ dest_mnt_ns = is_anon_ns(mp.parent->mnt_ns) ?
+ current->nsproxy->mnt_ns : mp.parent->mnt_ns;
+ if (!check_for_nsfs_mounts(old, dest_mnt_ns))
return -ELOOP;
if (mount_is_ancestor(old, mp.parent))
return -ELOOP;
- return attach_recursive_mnt(old, &mp);
+ return attach_recursive_mnt(old, &mp, src_user_ns);
}
static int do_move_mount_old(const struct path *path, const char *old_name)
@@ -3860,7 +3916,7 @@ static int do_move_mount_old(const struct path *path, const char *old_name)
if (err)
return err;
- return do_move_mount(&old_path, path, 0);
+ return do_move_mount(&old_path, path, 0, NULL);
}
/*
@@ -4725,7 +4781,8 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
static inline int vfs_move_mount(const struct path *from_path,
const struct path *to_path,
- enum mnt_tree_flags_t mflags)
+ enum mnt_tree_flags_t mflags,
+ struct mnt_namespace *target_mnt_ns)
{
int ret;
@@ -4736,7 +4793,123 @@ static inline int vfs_move_mount(const struct path *from_path,
if (mflags & MNT_TREE_PROPAGATION)
return do_set_group(from_path, to_path);
- return do_move_mount(from_path, to_path, mflags);
+ return do_move_mount(from_path, to_path, mflags, target_mnt_ns);
+}
+
+static int lookup_move_mount_from(int from_dfd,
+ const char __user *from_pathname,
+ unsigned int flags, struct path *from_path)
+{
+ unsigned int uflags = 0;
+ unsigned int lflags = 0;
+
+ if (flags & MOVE_MOUNT_F_EMPTY_PATH)
+ uflags = AT_EMPTY_PATH;
+
+ CLASS(filename_maybe_null, from_name)(from_pathname, uflags);
+ if (!from_name && from_dfd >= 0) {
+ CLASS(fd_raw, f_from)(from_dfd);
+ if (fd_empty(f_from))
+ return -EBADF;
+
+ *from_path = fd_file(f_from)->f_path;
+ path_get(from_path);
+ return 0;
+ }
+
+ if (flags & MOVE_MOUNT_F_SYMLINKS)
+ lflags |= LOOKUP_FOLLOW;
+ if (flags & MOVE_MOUNT_F_AUTOMOUNTS)
+ lflags |= LOOKUP_AUTOMOUNT;
+ return filename_lookup(from_dfd, from_name, lflags, from_path, NULL);
+}
+
+/**
+ * DOC: MOVE_MOUNT_T_MNTNS
+ *
+ * ``MOVE_MOUNT_T_MNTNS`` installs detached anonymous mount trees into a target
+ * mount namespace ``nsfs`` file descriptor supplied as ``to_dfd``:
+ *
+ * 1. ``to_pathname`` of ``"/"`` attaches the initial root mount onto the
+ * ``nullfs`` root of an empty mount namespace at most once.
+ *
+ * 2. Relative ``to_pathname`` values resolve beneath the live root of the
+ * target mount namespace.
+ *
+ * Capability is checked against ``CAP_SYS_ADMIN`` in the target mount
+ * namespace's owning user namespace, and source trees crossing user namespace
+ * boundaries are locked with ``MNT_LOCKED`` and locked mount flags.
+ */
+static int move_mount_mntns(int from_dfd, const char __user *from_pathname,
+ int to_dfd, const char __user *to_pathname,
+ unsigned int flags, enum mnt_tree_flags_t mflags)
+{
+ struct path from_path __free(path_put) = {};
+ struct path to_path __free(path_put) = {};
+ struct mnt_namespace *target_mnt_ns;
+ unsigned int lflags;
+ struct ns_common *ns;
+ bool is_root;
+ int ret;
+
+ CLASS(filename_maybe_null, to_name)(to_pathname, AT_EMPTY_PATH);
+ if (IS_ERR(to_name))
+ return PTR_ERR(to_name);
+ if (!to_name)
+ return -EINVAL;
+
+ CLASS(fd, f_mntns)(to_dfd);
+ if (fd_empty(f_mntns))
+ return -EBADF;
+ if (!proc_ns_file(fd_file(f_mntns)))
+ return -EINVAL;
+
+ ns = get_proc_ns(file_inode(fd_file(f_mntns)));
+ if (ns->ns_type != CLONE_NEWNS)
+ return -EINVAL;
+
+ target_mnt_ns = to_mnt_ns(ns);
+ if (is_anon_ns(target_mnt_ns))
+ return -EINVAL;
+ if (!ns_capable(target_mnt_ns->user_ns, CAP_SYS_ADMIN))
+ return -EPERM;
+
+ is_root = to_name->name[0] == '/' && to_name->name[1] == '\0';
+ if (is_root) {
+ if (flags & MOVE_MOUNT_BENEATH)
+ return -EINVAL;
+
+ to_path.mnt = mntget(&target_mnt_ns->root->mnt);
+ to_path.dentry = dget(target_mnt_ns->root->mnt.mnt_root);
+ mflags |= MNT_TREE_MNTNS_INIT;
+ } else {
+ struct path mntns_root __free(path_put) = {};
+
+ if (to_name->name[0] == '/')
+ return -EINVAL;
+
+ ret = mnt_ns_get_root(target_mnt_ns, &mntns_root);
+ if (ret)
+ return ret;
+
+ lflags = LOOKUP_IN_ROOT;
+ if (flags & MOVE_MOUNT_T_SYMLINKS)
+ lflags |= LOOKUP_FOLLOW;
+ if (flags & MOVE_MOUNT_T_AUTOMOUNTS)
+ lflags |= LOOKUP_AUTOMOUNT;
+ ret = filename_lookup(AT_FDCWD, to_name, lflags, &to_path,
+ &mntns_root);
+ if (ret)
+ return ret;
+ }
+
+ ret = lookup_move_mount_from(from_dfd, from_pathname, flags,
+ &from_path);
+ if (ret)
+ return ret;
+
+ return vfs_move_mount(&from_path, &to_path, mflags | MNT_TREE_MNTNS,
+ target_mnt_ns);
}
/*
@@ -4758,7 +4931,7 @@ SYSCALL_DEFINE5(move_mount,
enum mnt_tree_flags_t mflags = 0;
int ret = 0;
- if (!may_mount())
+ if (!(flags & MOVE_MOUNT_T_MNTNS) && !may_mount())
return -EPERM;
if (flags & ~MOVE_MOUNT__MASK)
@@ -4771,6 +4944,13 @@ SYSCALL_DEFINE5(move_mount,
if (flags & MOVE_MOUNT_SET_GROUP) mflags |= MNT_TREE_PROPAGATION;
if (flags & MOVE_MOUNT_BENEATH) mflags |= MNT_TREE_BENEATH;
+ if (unlikely(flags & MOVE_MOUNT_T_MNTNS)) {
+ if (flags & (MOVE_MOUNT_T_EMPTY_PATH | MOVE_MOUNT_SET_GROUP))
+ return -EINVAL;
+ return move_mount_mntns(from_dfd, from_pathname,
+ to_dfd, to_pathname, flags, mflags);
+ }
+
uflags = 0;
if (flags & MOVE_MOUNT_T_EMPTY_PATH)
uflags = AT_EMPTY_PATH;
@@ -4794,29 +4974,12 @@ SYSCALL_DEFINE5(move_mount,
return ret;
}
- uflags = 0;
- if (flags & MOVE_MOUNT_F_EMPTY_PATH)
- uflags = AT_EMPTY_PATH;
-
- CLASS(filename_maybe_null,from_name)(from_pathname, uflags);
- if (!from_name && from_dfd >= 0) {
- CLASS(fd_raw, f_from)(from_dfd);
- if (fd_empty(f_from))
- return -EBADF;
-
- return vfs_move_mount(&fd_file(f_from)->f_path, &to_path, mflags);
- }
-
- lflags = 0;
- if (flags & MOVE_MOUNT_F_SYMLINKS)
- lflags |= LOOKUP_FOLLOW;
- if (flags & MOVE_MOUNT_F_AUTOMOUNTS)
- lflags |= LOOKUP_AUTOMOUNT;
- ret = filename_lookup(from_dfd, from_name, lflags, &from_path, NULL);
+ ret = lookup_move_mount_from(from_dfd, from_pathname, flags,
+ &from_path);
if (ret)
return ret;
- return vfs_move_mount(&from_path, &to_path, mflags);
+ return vfs_move_mount(&from_path, &to_path, mflags, NULL);
}
/*
diff --git a/fs/pnode.c b/fs/pnode.c
index 5f07fa14099b..967188f37df7 100644
--- a/fs/pnode.c
+++ b/fs/pnode.c
@@ -9,6 +9,7 @@
#include <linux/mount.h>
#include <linux/fs.h>
#include <linux/nsproxy.h>
+#include <linux/user_namespace.h>
#include <uapi/linux/mount.h>
#include "internal.h"
#include "pnode.h"
@@ -271,6 +272,32 @@ static bool need_secondary(struct mount *m, struct mountpoint *dest_mp)
return true;
}
+/*
+ * A secondary in a user namespace without privilege over @src_user_ns must not
+ * reveal what non-expiring submounts of the source tree cover. Copies chain
+ * from earlier copies, so decide once for the whole propagation: a copy that
+ * silently dropped a submount for a privileged peer must not become the
+ * source for an unprivileged one.
+ */
+static bool need_lock_source(struct mount *dest_mnt, struct mountpoint *dest_mp,
+ struct user_namespace *src_user_ns)
+{
+ struct mount *m, *n;
+
+ if (!src_user_ns)
+ return false;
+
+ for (m = dest_mnt; m; m = next_group(m, dest_mnt)) {
+ n = m;
+ do {
+ if (n != dest_mnt && need_secondary(n, dest_mp) &&
+ !in_userns(n->mnt_ns->user_ns, src_user_ns))
+ return true;
+ } while ((n = next_peer(n)) != m);
+ }
+ return false;
+}
+
static struct mount *find_master(struct mount *m,
struct mount *last_copy,
struct mount *original)
@@ -302,6 +329,7 @@ static struct mount *find_master(struct mount *m,
* @dest_mp: destination mountpoint.
* @source_mnt: source mount.
* @tree_list: list of secondaries to be attached.
+ * @src_user_ns: owning user namespace of a foreign @source_mnt, or NULL.
*
* Create secondary copies for attaching a tree with root @source_mnt
* at mount @dest_mnt with mountpoint @dest_mp. Link all new mounts
@@ -309,10 +337,14 @@ static struct mount *find_master(struct mount *m,
* link their roots into @tree_list via ->mnt_hash.
*/
int propagate_mnt(struct mount *dest_mnt, struct mountpoint *dest_mp,
- struct mount *source_mnt, struct hlist_head *tree_list)
+ struct mount *source_mnt, struct hlist_head *tree_list,
+ struct user_namespace *src_user_ns)
{
struct mount *m, *n, *copy, *this;
- int err = 0, type;
+ int err = 0, type, lock_flag;
+
+ lock_flag = need_lock_source(dest_mnt, dest_mp, src_user_ns) ?
+ CL_LOCK_SOURCE : 0;
if (dest_mnt->mnt_master)
SET_MNT_MARK(dest_mnt->mnt_master);
@@ -337,7 +369,8 @@ int propagate_mnt(struct mount *dest_mnt, struct mountpoint *dest_mp,
continue;
if (type & CL_SLAVE) // first in this peer group
copy = find_master(n, copy, source_mnt);
- this = copy_tree(copy, copy->mnt.mnt_root, type);
+ this = copy_tree(copy, copy->mnt.mnt_root,
+ type | lock_flag);
if (IS_ERR(this)) {
err = PTR_ERR(this);
break;
diff --git a/fs/pnode.h b/fs/pnode.h
index b029db225f33..72be9cbfb998 100644
--- a/fs/pnode.h
+++ b/fs/pnode.h
@@ -26,6 +26,7 @@
#define CL_MAKE_SHARED 0x08
#define CL_PRIVATE 0x10
#define CL_COPY_MNT_NS_FILE 0x40
+#define CL_LOCK_SOURCE 0x80
/*
* EXCL[namespace_sem]
@@ -44,7 +45,7 @@ static inline bool peers(const struct mount *m1, const struct mount *m2)
void change_mnt_propagation(struct mount *, int);
void bulk_make_private(struct list_head *);
int propagate_mnt(struct mount *, struct mountpoint *, struct mount *,
- struct hlist_head *);
+ struct hlist_head *, struct user_namespace *);
void propagate_umount(struct list_head *);
int propagate_mount_busy(struct mount *, int);
void propagate_mount_unlock(struct mount *);
diff --git a/include/uapi/linux/mount.h b/include/uapi/linux/mount.h
index ac865edac517..7d413418426a 100644
--- a/include/uapi/linux/mount.h
+++ b/include/uapi/linux/mount.h
@@ -75,9 +75,10 @@
#define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */
#define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */
#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */
+#define MOVE_MOUNT_T_MNTNS 0x00000080 /* Resolve to_dfd as mntns fd */
#define MOVE_MOUNT_SET_GROUP 0x00000100 /* Set sharing group instead */
#define MOVE_MOUNT_BENEATH 0x00000200 /* Mount beneath top mount */
-#define MOVE_MOUNT__MASK 0x00000377
+#define MOVE_MOUNT__MASK 0x000003f7
/*
* fsopen() flags.
--
2.47.3
next prev parent reply other threads:[~2026-12-05 3:27 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 01/28] userns: Factor out idmap validation and commit helpers Jarkko Sakkinen
2026-12-05 4:01 ` bot+bpf-ci
2026-12-05 4:01 ` bot+bpf-ci
2026-12-05 14:13 ` Jarkko Sakkinen
2026-12-05 14:13 ` Jarkko Sakkinen
2026-12-05 14:22 ` Jarkko Sakkinen
2026-12-05 14:22 ` Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 02/28] userns: Add NS_SET_IDMAP ioctl Jarkko Sakkinen
2026-12-05 3:52 ` sashiko-bot
2026-12-05 4:02 ` bot+bpf-ci
2026-12-05 4:02 ` bot+bpf-ci
2026-12-05 13:47 ` Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 03/28] mount: Add mnt_ns_get_root() Jarkko Sakkinen
2026-12-05 3:46 ` sashiko-bot
2026-12-05 13:47 ` Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 04/28] mount: Enforce mount_too_revealing() for foreign mntns Jarkko Sakkinen
2026-12-05 3:54 ` sashiko-bot
2026-12-05 13:47 ` Jarkko Sakkinen
2026-12-05 3:26 ` Jarkko Sakkinen [this message]
2026-12-05 4:05 ` [RFC PATCH v10 05/28] mount: Support MOVE_MOUNT_T_MNTNS in move_mount() sashiko-bot
2026-12-05 3:26 ` [RFC PATCH v10 06/28] security: Pass flags to security_move_mount() Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 07/28] mount: Support MOVE_MOUNT_CLONE with MOVE_MOUNT_T_MNTNS Jarkko Sakkinen
2026-12-05 4:01 ` sashiko-bot
2026-12-05 3:26 ` [RFC PATCH v10 08/28] apparmor: Mediate MOVE_MOUNT_CLONE as recursive bind Jarkko Sakkinen
2026-12-05 3:51 ` sashiko-bot
2026-12-05 13:48 ` Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 09/28] userns: Factor out install_user_ns_cred() Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 10/28] nsproxy: Expose create_new_namespaces() Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 11/28] runfd: Add core infrastructure Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 12/28] runfd: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 13/28] runfd: Add runfd() system call Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 14/28] runfd: Add RUNFD_GET_NSFD ioctl Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 15/28] runfd: Add RUNFD_SHARE_NSFD ioctl Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 16/28] exit: Support P_RUNFD in waitid() Jarkko Sakkinen
2026-12-05 3:49 ` sashiko-bot
2026-12-05 13:48 ` Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 17/28] signal: Support run fds in pidfd_send_signal() Jarkko Sakkinen
2026-12-05 4:02 ` bot+bpf-ci
2026-12-05 4:02 ` bot+bpf-ci
2026-12-05 3:26 ` [RFC PATCH v10 18/28] fork: Support CLONE_INTO_RUN in clone3() Jarkko Sakkinen
2026-12-05 4:12 ` sashiko-bot
2026-12-05 4:17 ` bot+bpf-ci
2026-12-05 4:17 ` bot+bpf-ci
2026-12-05 3:26 ` [RFC PATCH v10 19/28] fs: Support FSCONFIG_SET_RUN in fsconfig() Jarkko Sakkinen
2026-12-05 4:02 ` sashiko-bot
2026-12-05 4:17 ` bot+bpf-ci
2026-12-05 4:17 ` bot+bpf-ci
2026-12-05 3:26 ` [RFC PATCH v10 20/28] proc: Implement ->set_run() fs_context operation Jarkko Sakkinen
2026-12-05 3:56 ` sashiko-bot
2026-12-05 4:02 ` bot+bpf-ci
2026-12-05 4:02 ` bot+bpf-ci
2026-12-05 13:48 ` Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 21/28] ipc/mqueue: " Jarkko Sakkinen
2026-12-05 3:52 ` sashiko-bot
2026-12-05 4:02 ` bot+bpf-ci
2026-12-05 4:02 ` bot+bpf-ci
2026-12-05 3:26 ` [RFC PATCH v10 22/28] security: Add run LSM hooks Jarkko Sakkinen
2026-12-05 4:02 ` bot+bpf-ci
2026-12-05 4:02 ` bot+bpf-ci
2026-12-05 4:09 ` sashiko-bot
2026-12-05 3:26 ` [RFC PATCH v10 23/28] landlock: Enforce namespace use restrictions on run Jarkko Sakkinen
2026-12-05 4:01 ` bot+bpf-ci
2026-12-05 4:01 ` bot+bpf-ci
2026-12-05 4:09 ` sashiko-bot
2026-12-05 3:26 ` [RFC PATCH v10 24/28] bpf: Register run LSM hooks Jarkko Sakkinen
2026-12-05 3:54 ` sashiko-bot
2026-12-05 13:48 ` Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 25/28] arch: Wire up runfd() system call Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 26/28] ioctl: Register the runfd ioctl range Jarkko Sakkinen
2026-12-05 3:52 ` bot+bpf-ci
2026-12-05 3:52 ` bot+bpf-ci
2026-12-05 3:53 ` sashiko-bot
2026-12-05 13:49 ` Jarkko Sakkinen
2026-12-05 3:26 ` [RFC PATCH v10 27/28] docs: Include runfd kernel-doc in the userspace API manual Jarkko Sakkinen
2026-12-05 4:04 ` sashiko-bot
2026-12-05 3:26 ` [RFC PATCH v10 28/28] MAINTAINERS: Add entry for RUNFD Jarkko Sakkinen
2026-12-05 4:12 ` [RFC PATCH v10 00/28] runfd: Staged namespace execution sashiko-bot
2026-12-05 16:56 ` Jarkko Sakkinen
2026-12-05 17:19 ` Jarkko Sakkinen
2026-12-05 18:53 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205032633.1702772-6-jarkko@kernel.org \
--to=jarkko@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=aleksa@amutable.com \
--cc=alex@amutable.com \
--cc=andrii@kernel.org \
--cc=arnd@arndb.de \
--cc=ast@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=bsegall@google.com \
--cc=containers@lists.linux.dev \
--cc=corbet@lwn.net \
--cc=daniel@iogearbox.net \
--cc=dave@stgolabs.net \
--cc=david@kernel.org \
--cc=dhowells@redhat.com \
--cc=dietmar.eggemann@arm.com \
--cc=dwmw2@infradead.org \
--cc=ebiggers@kernel.org \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=fsdevel@vger.kernel.org \
--cc=georgia.garcia@canonical.com \
--cc=giuseppe@scrivano.org \
--cc=gnoack@google.com \
--cc=hughd@google.com \
--cc=ihor.solodrai@linux.dev \
--cc=jack@suse.cz \
--cc=jgg@nvidia.com \
--cc=jlayton@kernel.org \
--cc=jmorris@namei.org \
--cc=john.johansen@canonical.com \
--cc=jolsa@kernel.org \
--cc=josef@toxicpanda.com \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kprateek.nayak@amd.com \
--cc=kpsingh@kernel.org \
--cc=lennart@poettering.net \
--cc=liam@infradead.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-security-module@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=manfred@colorfullife.com \
--cc=martin.lau@linux.dev \
--cc=matt@bobrowski.net \
--cc=memxor@gmail.com \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=mic@digikod.net \
--cc=mingo@redhat.com \
--cc=neal@gompa.dev \
--cc=oleg@redhat.com \
--cc=paul@paul-moore.com \
--cc=peterz@infradead.org \
--cc=ptikhomirov@virtuozzo.com \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=serge@hallyn.com \
--cc=sergeh@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=song@kernel.org \
--cc=stephen.smalley.work@gmail.com \
--cc=vincent.guittot@linaro.org \
--cc=viro@zeniv.linux.org.uk \
--cc=vschneid@redhat.com \
--cc=yonghong.song@linux.dev \
--cc=zygmunt.krynicki@canonical.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.