fix the softlockups in attach_recursive_mnt()
authorAl Viro <viro@zeniv.linux.org.uk>
Fri, 15 Aug 2025 19:38:14 +0000 (15:38 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 19 Aug 2025 15:58:18 +0000 (11:58 -0400)
commit0ddfb62f5d018edcb571a3d8ea30ad5332cf2a69
tree0ebcb9ab807cebd06512f8ec89956c56c94882c1
parent8742b2d8935f476449ef37e263bc4da3295c7b58
fix the softlockups in attach_recursive_mnt()

In case when we mounting something on top of a large stack of overmounts,
all of them being peers of each other, we get quadratic time by the
depth of overmount stack.  Easily fixed by doing commit_tree() before
reparenting the overmount; simplifies commit_tree() as well - it doesn't
need to skip the already mounted stuff that had been reparented on top
of the new mounts.

Since we are holding mount_lock through both reparenting and call of
commit_tree(), the order does not matter from the mount hash point
of view.

Reported-by: "Lai, Yi" <yi1.lai@linux.intel.com>
Tested-by: "Lai, Yi" <yi1.lai@linux.intel.com>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Fixes: 663206854f02 "copy_tree(): don't link the mounts via mnt_list"
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/namespace.c