summaryrefslogtreecommitdiff
path: root/fs/namespace.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2025-08-26 16:59:16 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2025-09-15 21:26:44 -0400
commit57a7b5b0b6d9b92871bffcc21865ec07d5c8b297 (patch)
treea0e97003bc196f0dd21e3f0468d0f9e822defb6a /fs/namespace.c
parent71cf10ce4562ed7b18f3bd44a4e2dfafd0e84c50 (diff)
open_detached_copy(): separate creation of namespace into helper
... and convert the helper to use of a guard(namespace_excl) Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/namespace.c')
-rw-r--r--fs/namespace.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/fs/namespace.c b/fs/namespace.c
index 468ae0cb475e..4ebd9cc6f6c6 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -3047,18 +3047,17 @@ static int do_loopback(const struct path *path, const char *old_name,
return err;
}
-static struct file *open_detached_copy(struct path *path, bool recursive)
+static struct mnt_namespace *get_detached_copy(const struct path *path, bool recursive)
{
struct mnt_namespace *ns, *mnt_ns = current->nsproxy->mnt_ns, *src_mnt_ns;
struct user_namespace *user_ns = mnt_ns->user_ns;
struct mount *mnt, *p;
- struct file *file;
ns = alloc_mnt_ns(user_ns, true);
if (IS_ERR(ns))
- return ERR_CAST(ns);
+ return ns;
- namespace_lock();
+ guard(namespace_excl)();
/*
* Record the sequence number of the source mount namespace.
@@ -3075,8 +3074,7 @@ static struct file *open_detached_copy(struct path *path, bool recursive)
mnt = __do_loopback(path, recursive);
if (IS_ERR(mnt)) {
- namespace_unlock();
- free_mnt_ns(ns);
+ emptied_ns = ns;
return ERR_CAST(mnt);
}
@@ -3085,11 +3083,19 @@ static struct file *open_detached_copy(struct path *path, bool recursive)
ns->nr_mounts++;
}
ns->root = mnt;
- mntget(&mnt->mnt);
- namespace_unlock();
+ return ns;
+}
+
+static struct file *open_detached_copy(struct path *path, bool recursive)
+{
+ struct mnt_namespace *ns = get_detached_copy(path, recursive);
+ struct file *file;
+
+ if (IS_ERR(ns))
+ return ERR_CAST(ns);
mntput(path->mnt);
- path->mnt = &mnt->mnt;
+ path->mnt = mntget(&ns->root->mnt);
file = dentry_open(path, O_PATH, current_cred());
if (IS_ERR(file))
dissolve_on_fput(path->mnt);