aboutsummaryrefslogtreecommitdiffstats
path: root/fs/namespace.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2025-07-02 01:39:45 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2025-09-02 19:35:57 -0400
commit6b6516c56b04d556ce57deab1b8c2833e4af26c6 (patch)
treee4f28409d1ceaa38c72a3453717eb447421e8b7e /fs/namespace.c
parent2aec880c1cdf1cf2dab931b4dd8744c415311bc9 (diff)
downloadrandom-6b6516c56b04d556ce57deab1b8c2833e4af26c6.tar.gz
current_chrooted(): don't bother with follow_down_one()
All we need here is to follow ->overmount on root mount of namespace... 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.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/fs/namespace.c b/fs/namespace.c
index 6aabf0045389c5..cf680fbf015e9f 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -6194,24 +6194,22 @@ bool our_mnt(struct vfsmount *mnt)
bool current_chrooted(void)
{
/* Does the current process have a non-standard root */
- struct path ns_root;
+ struct mount *root = current->nsproxy->mnt_ns->root;
struct path fs_root;
bool chrooted;
+ get_fs_root(current->fs, &fs_root);
+
/* Find the namespace root */
- ns_root.mnt = &current->nsproxy->mnt_ns->root->mnt;
- ns_root.dentry = ns_root.mnt->mnt_root;
- path_get(&ns_root);
- while (d_mountpoint(ns_root.dentry) && follow_down_one(&ns_root))
- ;
+ read_seqlock_excl(&mount_lock);
- get_fs_root(current->fs, &fs_root);
+ while (unlikely(root->overmount))
+ root = root->overmount;
- chrooted = !path_equal(&fs_root, &ns_root);
+ chrooted = fs_root.mnt != &root->mnt || !path_mounted(&fs_root);
+ read_sequnlock_excl(&mount_lock);
path_put(&fs_root);
- path_put(&ns_root);
-
return chrooted;
}