From: Al Viro Date: Fri, 22 Aug 2025 01:02:06 +0000 (-0400) Subject: current_chrooted(): use guards X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=8281f98a68d3306b2e47e6bb00708525562ccfdf;p=users%2Fhch%2Fmisc.git current_chrooted(): use guards here a use of __free(path_put) for dropping fs_root is enough to make guard(mount_locked_reader) fit... Reviewed-by: Christian Brauner Signed-off-by: Al Viro --- diff --git a/fs/namespace.c b/fs/namespace.c index cf680fbf015e..0474b3a93dbf 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -6194,23 +6194,20 @@ bool our_mnt(struct vfsmount *mnt) bool current_chrooted(void) { /* Does the current process have a non-standard root */ - struct mount *root = current->nsproxy->mnt_ns->root; - struct path fs_root; - bool chrooted; + struct path fs_root __free(path_put) = {}; + struct mount *root; get_fs_root(current->fs, &fs_root); /* Find the namespace root */ - read_seqlock_excl(&mount_lock); + guard(mount_locked_reader)(); + + root = current->nsproxy->mnt_ns->root; while (unlikely(root->overmount)) root = root->overmount; - chrooted = fs_root.mnt != &root->mnt || !path_mounted(&fs_root); - - read_sequnlock_excl(&mount_lock); - path_put(&fs_root); - return chrooted; + return fs_root.mnt != &root->mnt || !path_mounted(&fs_root); } static bool mnt_already_visible(struct mnt_namespace *ns,