]> www.infradead.org Git - users/hch/misc.git/commitdiff
path_is_under(): use guards
authorAl Viro <viro@zeniv.linux.org.uk>
Fri, 22 Aug 2025 00:48:38 +0000 (20:48 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 2 Sep 2025 23:35:57 +0000 (19:35 -0400)
... and document that locking requirements for is_path_reachable().
There is one questionable caller in do_listmount() where we are not
holding mount_lock *and* might not have the first argument mounted.
However, in that case it will immediately return true without having
to look at the ancestors.  Might be cleaner to move the check into
non-LSTM_ROOT case which it really belongs in - there the check is
not always true and is_mounted() is guaranteed.

Document the locking environments for is_path_reachable() callers:
get_peer_under_root()
get_dominating_id()
do_statmount()
do_listmount()

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

index db25c81d7f68f42ce11d5f25911b557663ceb1ea..6aabf0045389c5ebfda7c1e4725143c7fffa0732 100644 (file)
@@ -4592,7 +4592,7 @@ SYSCALL_DEFINE5(move_mount,
 /*
  * Return true if path is reachable from root
  *
- * namespace_sem or mount_lock is held
+ * locks: mount_locked_reader || namespace_shared && is_mounted(mnt)
  */
 bool is_path_reachable(struct mount *mnt, struct dentry *dentry,
                         const struct path *root)
@@ -4606,11 +4606,8 @@ bool is_path_reachable(struct mount *mnt, struct dentry *dentry,
 
 bool path_is_under(const struct path *path1, const struct path *path2)
 {
-       bool res;
-       read_seqlock_excl(&mount_lock);
-       res = is_path_reachable(real_mount(path1->mnt), path1->dentry, path2);
-       read_sequnlock_excl(&mount_lock);
-       return res;
+       guard(mount_locked_reader)();
+       return is_path_reachable(real_mount(path1->mnt), path1->dentry, path2);
 }
 EXPORT_SYMBOL(path_is_under);
 
@@ -5689,6 +5686,7 @@ static int grab_requested_root(struct mnt_namespace *ns, struct path *root)
                             STATMOUNT_MNT_UIDMAP | \
                             STATMOUNT_MNT_GIDMAP)
 
+/* locks: namespace_shared */
 static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
                        struct mnt_namespace *ns)
 {
@@ -5949,6 +5947,7 @@ retry:
        return ret;
 }
 
+/* locks: namespace_shared */
 static ssize_t do_listmount(struct mnt_namespace *ns, u64 mnt_parent_id,
                            u64 last_mnt_id, u64 *mnt_ids, size_t nr_mnt_ids,
                            bool reverse)
index 0702d45d856dd9f7513236ddc2b28293326b93c0..edaf9d9d0eaf03c8fe74111f024d2085976faac1 100644 (file)
@@ -29,6 +29,7 @@ static inline struct mount *next_slave(struct mount *p)
        return hlist_entry(p->mnt_slave.next, struct mount, mnt_slave);
 }
 
+/* locks: namespace_shared && is_mounted(mnt) */
 static struct mount *get_peer_under_root(struct mount *mnt,
                                         struct mnt_namespace *ns,
                                         const struct path *root)
@@ -50,7 +51,7 @@ static struct mount *get_peer_under_root(struct mount *mnt,
  * Get ID of closest dominating peer group having a representative
  * under the given root.
  *
- * Caller must hold namespace_sem
+ * locks: namespace_shared
  */
 int get_dominating_id(struct mount *mnt, const struct path *root)
 {