]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
attach_recursive_mnt(): do not lock the covering tree when sliding something under it
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 22 Jun 2025 22:03:29 +0000 (18:03 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Mon, 23 Jun 2025 18:02:08 +0000 (14:02 -0400)
If we are propagating across the userns boundary, we need to lock the
mounts added there.  However, in case when something has already
been mounted there and we end up sliding a new tree under that,
the stuff that had been there before should not get locked.

IOW, lock_mnt_tree() should be called before we reparent the
preexisting tree on top of what we are adding.

Fixes: 3bd045cc9c4b ("separate copying and locking mount tree on cross-userns copies")
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/namespace.c

index 14601ec4c2c5bbc8773d5d67adc5e5fdc7dd1200..eed83254492f3097b7835c89a9941adf3b74b1c2 100644 (file)
@@ -2768,14 +2768,14 @@ static int attach_recursive_mnt(struct mount *source_mnt,
        hlist_for_each_entry_safe(child, n, &tree_list, mnt_hash) {
                struct mount *q;
                hlist_del_init(&child->mnt_hash);
-               q = __lookup_mnt(&child->mnt_parent->mnt,
-                                child->mnt_mountpoint);
-               if (q)
-                       mnt_change_mountpoint(child, smp, q);
                /* Notice when we are propagating across user namespaces */
                if (child->mnt_parent->mnt_ns->user_ns != user_ns)
                        lock_mnt_tree(child);
                child->mnt.mnt_flags &= ~MNT_LOCKED;
+               q = __lookup_mnt(&child->mnt_parent->mnt,
+                                child->mnt_mountpoint);
+               if (q)
+                       mnt_change_mountpoint(child, smp, q);
                commit_tree(child);
        }
        put_mountpoint(smp);