[PATCH] [FOLD]: Don't allow to abuse restricted procfs mounts to mount unrestricted ones

From: Christian Brauner

Date: Thu Apr 16 2026 - 09:22:15 EST


Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx>
---
fs/namespace.c | 11 ++++++++++-
fs/proc/root.c | 5 ++++-
include/linux/fs/super_types.h | 1 +
3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 7b171a67dd50..099ce44e46b5 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -6351,10 +6351,19 @@ static bool mnt_already_visible(struct mnt_namespace *ns,

guard(namespace_shared)();
hlist_for_each_entry(mnt, &ns->mnt_visible_mounts, mnt_ns_visible) {
+ const struct super_block *sb_visible = mnt->mnt.mnt_sb;
struct mount *child;
int mnt_flags;

- if (mnt->mnt.mnt_sb->s_type != sb->s_type)
+ if (sb_visible->s_type != sb->s_type)
+ continue;
+
+ /*
+ * If the new superblock is not going to be restricted then any
+ * mount that is restricted cannot be used to allow it.
+ */
+ if (!(sb->s_iflags & SB_I_USERNS_RESTRICTED) &&
+ (sb_visible->s_iflags & SB_I_USERNS_RESTRICTED))
continue;

/* A local view of the mount flags */
diff --git a/fs/proc/root.c b/fs/proc/root.c
index 350fc4f888ab..a035467b465b 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -267,8 +267,11 @@ static int proc_fill_super(struct super_block *s, struct fs_context *fc)
* The dynamic part of procfs cannot be hidden using overmount.
* Therefore, the check for "not fully visible" can be skipped.
*/
- if (fs_info->pidonly)
+ if (fs_info->pidonly) {
fc->skip_visibility = true;
+ /* Indicate that this procfs instance hides a bunch of files. */
+ s->s_iflags |= SB_I_USERNS_RESTRICTED;
+ }

/* User space would break if executables or devices appear on proc */
s->s_iflags |= SB_I_NOEXEC | SB_I_NODEV;
diff --git a/include/linux/fs/super_types.h b/include/linux/fs/super_types.h
index 182efbeb9520..4ae7d0c3d55b 100644
--- a/include/linux/fs/super_types.h
+++ b/include/linux/fs/super_types.h
@@ -326,6 +326,7 @@ struct super_block {
#define SB_I_STABLE_WRITES 0x00000008 /* don't modify blks until WB is done */

/* sb->s_iflags to limit user namespace mounts */
+#define SB_I_USERNS_RESTRICTED 0x00000010
#define SB_I_IMA_UNVERIFIABLE_SIGNATURE 0x00000020
#define SB_I_UNTRUSTED_MOUNTER 0x00000040
#define SB_I_EVM_HMAC_UNSUPPORTED 0x00000080
--
2.47.3


--nfsjwfyis4t5hlj3
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
filename="0001-fs-move-SB_I_USERNS_VISIBLE-to-FS_USERNS_MOUNT_RESTR.patch"