lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20201015013739.1969680-1-andrii@kernel.org>
Date:   Wed, 14 Oct 2020 18:37:39 -0700
From:   Andrii Nakryiko <andrii@...nel.org>
To:     <viro@...iv.linux.org.uk>, <linux-fsdevel@...r.kernel.org>
CC:     <torvalds@...ux-foundation.org>, <kernel-team@...com>,
        <linux-kernel@...r.kernel.org>, Andrii Nakryiko <andrii@...nel.org>
Subject: [PATCH] fs: clean up is_mounted() check with extra helper

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@...iv.linux.org.uk>
Signed-off-by: Andrii Nakryiko <andrii@...nel.org>
---
 fs/d_path.c | 3 +--
 fs/mount.h  | 9 +++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/d_path.c b/fs/d_path.c
index a69e2cd36e6e..300bf675f097 100644
--- a/fs/d_path.c
+++ b/fs/d_path.c
@@ -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
diff --git a/fs/mount.h b/fs/mount.h
index c7abb7b394d8..0b0eb18ba80a 100644
--- a/fs/mount.h
+++ b/fs/mount.h
@@ -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 *);
-- 
2.24.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ