[PATCH 1/2] mount: pass flags to alloc_mnt_ns()
Christian Brauner
brauner at kernel.org
Fri Nov 20 12:29:58 UTC 2026
Turn the anon argument of alloc_mnt_ns() into a flags argument. The
next patch needs to pass another property of the new mount namespace
and two booleans in a row would make the callers unreadable.
No functional changes.
Signed-off-by: Christian Brauner (Amutable) <brauner at kernel.org>
---
fs/namespace.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index aecd05ac01705..756f9011cbf1d 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2353,7 +2353,12 @@ void drop_collected_paths(const struct path *paths, const struct path *prealloc)
kfree(paths);
}
-static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *, bool);
+enum mnt_ns_flags_t {
+ MNT_NS_ANON = (1 << 0),
+};
+
+static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *,
+ enum mnt_ns_flags_t);
/* Consumes the caller's reference to @mnt. */
void dissolve_on_fput(struct vfsmount *mnt)
@@ -3149,7 +3154,7 @@ static struct mnt_namespace *get_detached_copy(const struct path *path, unsigned
struct user_namespace *user_ns = mnt_ns->user_ns;
struct mount *mnt, *p;
- ns = alloc_mnt_ns(user_ns, true);
+ ns = alloc_mnt_ns(user_ns, MNT_NS_ANON);
if (IS_ERR(ns))
return ns;
@@ -3230,7 +3235,7 @@ static struct mnt_namespace *create_new_namespace(struct path *path,
if (foreign)
copy_flags |= CL_SLAVE | CL_COPY_UNBINDABLE;
- new_ns = alloc_mnt_ns(user_ns, false);
+ new_ns = alloc_mnt_ns(user_ns, 0);
if (IS_ERR(new_ns))
return ERR_CAST(new_ns);
@@ -4369,7 +4374,8 @@ static void free_mnt_ns(struct mnt_namespace *ns)
mnt_ns_tree_remove(ns);
}
-static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool anon)
+static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns,
+ enum mnt_ns_flags_t flags)
{
struct mnt_namespace *new_ns;
struct ucounts *ucounts;
@@ -4385,7 +4391,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool a
return ERR_PTR(-ENOMEM);
}
- if (anon)
+ if (flags & MNT_NS_ANON)
ret = ns_common_init_inum(new_ns, MNT_NS_ANON_INO);
else
ret = ns_common_init(new_ns);
@@ -4394,7 +4400,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool a
dec_mnt_namespaces(ucounts);
return ERR_PTR(ret);
}
- new_ns->is_anon = anon;
+ new_ns->is_anon = flags & MNT_NS_ANON;
refcount_set(&new_ns->passive, 1);
new_ns->mounts = RB_ROOT;
init_waitqueue_head(&new_ns->poll);
@@ -4422,7 +4428,7 @@ struct mnt_namespace *copy_mnt_ns(u64 flags, struct mnt_namespace *ns,
old = ns->root;
- new_ns = alloc_mnt_ns(user_ns, false);
+ new_ns = alloc_mnt_ns(user_ns, 0);
if (IS_ERR(new_ns))
return new_ns;
@@ -4509,7 +4515,7 @@ struct dentry *mount_subtree(struct vfsmount *m, const char *name)
struct path path;
int err;
- ns = alloc_mnt_ns(&init_user_ns, true);
+ ns = alloc_mnt_ns(&init_user_ns, MNT_NS_ANON);
if (IS_ERR(ns)) {
mntput(m);
return ERR_CAST(ns);
@@ -4699,7 +4705,7 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
return FD_ADD((flags & FSMOUNT_CLOEXEC) ? O_CLOEXEC : 0,
open_new_namespace(&new_path, MOUNT_COPY_NEW));
- ns = alloc_mnt_ns(current->nsproxy->mnt_ns->user_ns, true);
+ ns = alloc_mnt_ns(current->nsproxy->mnt_ns->user_ns, MNT_NS_ANON);
if (IS_ERR(ns))
return PTR_ERR(ns);
mnt = real_mount(new_path.mnt);
--
2.53.0
More information about the Linux-security-module-archive
mailing list