]> www.infradead.org Git - users/hch/misc.git/commitdiff
check_for_nsfs_mounts(): no need to take locks
authorAl Viro <viro@zeniv.linux.org.uk>
Thu, 21 Aug 2025 00:28:35 +0000 (20:28 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 2 Sep 2025 23:35:57 +0000 (19:35 -0400)
Currently we are taking mount_writer; what that function needs is
either mount_locked_reader (we are not changing anything, we just
want to iterate through the subtree) or namespace_shared and
a reference held by caller on the root of subtree - that's also
enough to stabilize the topology.

The thing is, all callers are already holding at least namespace_shared
as well as a reference to the root of subtree.

Let's make the callers provide locking warranties - don't mess with
mount_lock in check_for_nsfs_mounts() itself and document the locking
requirements.

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

index a5d37b97088f5fb01f5156eb65a3046bdaed8486..59948cbf9c47f7e7436b27e953b2ec9987af35df 100644 (file)
@@ -2402,21 +2402,15 @@ bool has_locked_children(struct mount *mnt, struct dentry *dentry)
  * specified subtree.  Such references can act as pins for mount namespaces
  * that aren't checked by the mount-cycle checking code, thereby allowing
  * cycles to be made.
+ *
+ * locks: mount_locked_reader || namespace_shared && pinned(subtree)
  */
 static bool check_for_nsfs_mounts(struct mount *subtree)
 {
-       struct mount *p;
-       bool ret = false;
-
-       lock_mount_hash();
-       for (p = subtree; p; p = next_mnt(p, subtree))
+       for (struct mount *p = subtree; p; p = next_mnt(p, subtree))
                if (mnt_ns_loop(p->mnt.mnt_root))
-                       goto out;
-
-       ret = true;
-out:
-       unlock_mount_hash();
-       return ret;
+                       return false;
+       return true;
 }
 
 /**