aboutsummaryrefslogtreecommitdiffstats
path: root/fs/namespace.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2025-08-20 03:23:12 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2025-09-15 21:26:05 -0400
commit25423edc787842d17520b3f9df4d0a58a6a663b1 (patch)
treeedcb63f6345d6a5373d02bc889be1dc3c350bec1 /fs/namespace.c
parented8ba4aad78887d88231c1c66c0ddf9fe12aaad1 (diff)
downloadrandom-25423edc787842d17520b3f9df4d0a58a6a663b1.tar.gz
new helper: topmost_overmount()
Returns the final (topmost) mount in the chain of overmounts starting at given mount. Same locking rules as for any mount tree traversal - either the spinlock side of mount_lock, or rcu + sample the seqcount side of mount_lock before the call and recheck afterwards. Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/namespace.c')
-rw-r--r--fs/namespace.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/fs/namespace.c b/fs/namespace.c
index b48bfb46b351d1..b6983adaa73b7a 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2696,10 +2696,9 @@ static int attach_recursive_mnt(struct mount *source_mnt,
child->mnt_mountpoint);
commit_tree(child);
if (q) {
+ struct mount *r = topmost_overmount(child);
struct mountpoint *mp = root.mp;
- struct mount *r = child;
- while (unlikely(r->overmount))
- r = r->overmount;
+
if (unlikely(shorter) && child != source_mnt)
mp = shorter;
mnt_change_mountpoint(r, mp, q);
@@ -6168,9 +6167,7 @@ bool current_chrooted(void)
guard(mount_locked_reader)();
- root = current->nsproxy->mnt_ns->root;
- while (unlikely(root->overmount))
- root = root->overmount;
+ root = topmost_overmount(current->nsproxy->mnt_ns->root);
return fs_root.mnt != &root->mnt || !path_mounted(&fs_root);
}