@@ -119,8 +119,7 @@ static int prepend_path(const struct path *path,
continue;
}
mnt_ns = READ_ONCE(mnt->mnt_ns);
- /* open-coded is_mounted() to use local mnt_ns */
- if (!IS_ERR_OR_NULL(mnt_ns) && !is_anon_ns(mnt_ns))
+ if (is_real_ns(mnt_ns) && !is_anon_ns(mnt_ns))
error = 1; // absolute root
else
error = 2; // detached or not attached yet
@@ -92,10 +92,15 @@ static inline int mnt_has_parent(struct mount *mnt)
return mnt != mnt->mnt_parent;
}
-static inline int is_mounted(struct vfsmount *mnt)
+static inline bool is_real_ns(const struct mnt_namespace *mnt_ns)
{
/* neither detached nor internal? */
- return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
+ return mnt_ns && mnt_ns != MNT_NS_INTERNAL;
+}
+
+static inline int is_mounted(struct vfsmount *mnt)
+{
+ return is_real_ns(real_mount(mnt)->mnt_ns);
}
extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
Add is_real_ns() helper validating that mount namespace is a valid one. Use that from is_mounted() and clean up prepare_path() that open-coded similar check. Suggested-by: Alexander Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> --- fs/d_path.c | 3 +-- fs/mount.h | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-)