]> www.infradead.org Git - users/hch/misc.git/commitdiff
copy_mnt_ns(): use guards
authorAl Viro <viro@zeniv.linux.org.uk>
Tue, 26 Aug 2025 21:12:15 +0000 (17:12 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 17 Sep 2025 19:58:28 +0000 (15:58 -0400)
* mntput() of rootmnt and pwdmnt done via __free(mntput)
* mnt_ns_tree_add() can be done within namespace_excl scope.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/namespace.c

index b4374d6d4bae2e82c4c8df0c36cbb9857fac8e6b..b5a082fae006662b7230719f580a1b896eb72f77 100644 (file)
@@ -4158,7 +4158,8 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
                struct user_namespace *user_ns, struct fs_struct *new_fs)
 {
        struct mnt_namespace *new_ns;
-       struct vfsmount *rootmnt = NULL, *pwdmnt = NULL;
+       struct vfsmount *rootmnt __free(mntput) = NULL;
+       struct vfsmount *pwdmnt __free(mntput) = NULL;
        struct mount *p, *q;
        struct mount *old;
        struct mount *new;
@@ -4177,7 +4178,7 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
        if (IS_ERR(new_ns))
                return new_ns;
 
-       namespace_lock();
+       guard(namespace_excl)();
        /* First pass: copy the tree topology */
        copy_flags = CL_COPY_UNBINDABLE | CL_EXPIRE;
        if (user_ns != ns->user_ns)
@@ -4185,13 +4186,11 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
        new = copy_tree(old, old->mnt.mnt_root, copy_flags);
        if (IS_ERR(new)) {
                emptied_ns = new_ns;
-               namespace_unlock();
                return ERR_CAST(new);
        }
        if (user_ns != ns->user_ns) {
-               lock_mount_hash();
+               guard(mount_writer)();
                lock_mnt_tree(new);
-               unlock_mount_hash();
        }
        new_ns->root = new;
 
@@ -4223,13 +4222,6 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
                while (p->mnt.mnt_root != q->mnt.mnt_root)
                        p = next_mnt(skip_mnt_tree(p), old);
        }
-       namespace_unlock();
-
-       if (rootmnt)
-               mntput(rootmnt);
-       if (pwdmnt)
-               mntput(pwdmnt);
-
        mnt_ns_tree_add(new_ns);
        return new_ns;
 }