From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796441226; b=abWiQk4zXwLzslbvI9qpfMpiyTMUJksYXTafgVXmDSHpNp/kiR1mKen8G/CYC4oGpIOy vsmU56zUhngb33WdeEeQBkt1opSZzBmAdRjpJdNqU1somdFlS09FvCoDzBACrRCpVYkdN EP+qaNCUOI9tWP9pj8KUJF/OL6Nmv6+BS21sBuQguRiCCEp5mMdtZKgDoccGRFTw36wHI IpREIWKueKpqOLk5Ek7xkJ3Cpm2EC9R+6yp5RrGD4bbFkFC2k3DkTNtuBfxB2CADIxNRJ lSexgI4o4VtLWa5F7CuOScSTyQ3U3XnzbE+8fpm10pOjMy12z3r4MeFMJfEsmvNTc9Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796441226; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=l3BxF7eKc8H9WX2SeKI00rPkbSvVT1UJBee/DhqmTQQ=; b=nc2Nb9FgxEa3e9Z/qljDxkCCtQsVWh/vTNGYr/IT2nqDOVqU+slopeZmtWbJSYym+8QX 7lkUp7S6rEXzi0RAqkI3ZZezVSjFwTEMqdy+nLeCQYxvioXGNHm9chezcb4TVJBGQddqW +h6qavhI4RZ48f/lORFhDAQSmlIbSw5G4fBV47Ovj8EotRnt24kZPQ917vShPe9S4jbgS 1nZXKWl1WVOd+7HDl+M0++IYFB54s9IVzNTvWihuhOezei37vfZpBwLgBfYOQ2l8ZiCGV vVnFg6S+xOm7nZOPKWIo7XFaANfrPwy8TpdonoPGqdKr9TtcINFKbjvaLEXHgnOOr+w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Cst5ndY3; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id 3ACCA606A322; Sat, 5 Dec 2026 03:27:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Cst5ndY3 Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 0F2571F0092B; Sat, 5 Dec 2026 03:27:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796441225; bh=l3BxF7eKc8H9WX2SeKI00rPkbSvVT1UJBee/DhqmTQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Cst5ndY3hD6+vqPKOWe+bgfuXO12tvgEzUeXzZBtXgFt4warioW5izggy6qsBCEwG IP96RkvcTlzlyrO6PJJzXUZJ1s2Y4FwZqUFF27qSXO8a/0LAus3OHphv3xm3bFn7VU gkT6vAZnHMk6rR7sSf4CtDgjJ2A+fZWyPytVTm4TWj/N3eMiNmVJwHQtzZGBUs5JlP rnxQvLsEgQ7vSfsnlh234O5DJG/TLjmrqV1ocN6y8fLbI68t5jUN9/jsTB99uolyre I5COB6uU6NC9TMhpM5KMHdWJDDOUcTT65vX01P9BERhK8F/p5JvPyWKFQ3yb53nor2 j+yZ3CDse6afw== From: Jarkko Sakkinen To: fsdevel@vger.kernel.org Cc: Jarkko Sakkinen , bpf@vger.kernel.org, containers@lists.linux.dev, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, Aleksa Sarai , Alexander Mikhalitsyn , Alexander Viro , Alexei Starovoitov , Andrew Morton , Andrii Nakryiko , Andy Lutomirski , Arnd Bergmann , Baolin Wang , Ben Segall , Christian Brauner , Daniel Borkmann , David Hildenbrand , David Howells , David Woodhouse , Davidlohr Bueso , Dietmar Eggemann , Eduard Zingerman , Emil Tsalapatis , Eric Biggers , Georgia Garcia , Giuseppe Scrivano , =?UTF-8?q?G=C3=BCnther=20Noack?= , Hugh Dickins , Ihor Solodrai , Ingo Molnar , James Morris , Jan Kara , Jason Gunthorpe , Jeff Layton , Jiri Olsa , John Johansen , Jonathan Corbet , Josef Bacik , Juri Lelli , Kees Cook , K Prateek Nayak , KP Singh , Kumar Kartikeya Dwivedi , Lennart Poettering , "Liam R. Howlett" , Manfred Spraul , Martin KaFai Lau , Matt Bobrowski , Mel Gorman , Michal Hocko , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Mike Rapoport , Neal Gompa , Oleg Nesterov , Paul Moore , Pavel Tikhomirov , Peter Zijlstra , Randy Dunlap , "Serge E. Hallyn" , Serge Hallyn , Shuah Khan , Song Liu , Stephen Smalley , Steven Rostedt , Valentin Schneider , Vincent Guittot , Yonghong Song , Zygmunt Krynicki Subject: [RFC PATCH v10 04/28] mount: Enforce mount_too_revealing() for foreign mntns Date: Sat, 5 Dec 2026 05:26:09 +0200 Message-ID: <20261205032633.1702772-5-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261205032633.1702772-1-jarkko@kernel.org> References: <20261205032633.1702772-1-jarkko@kernel.org> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit mount_too_revealing() skips visibility checks whenever current->nsproxy->mnt_ns belongs to init_user_ns, assuming the caller holds CAP_SYS_ADMIN in its current mount namespace. That assumption does not hold when an unprivileged caller creates mounts for a child user namespace while running in init_mnt_ns or another foreign mount namespace. Require CAP_SYS_ADMIN in init_user_ns before bypassing mount_too_revealing() for init_mnt_ns, reject chrooted callers lacking CAP_SYS_ADMIN in their current mount namespace, and treat existing mounts and child overmounts in a foreign mount namespace as locked during mnt_already_visible() checks. Co-developed-by: David Howells Signed-off-by: David Howells Signed-off-by: Jarkko Sakkinen --- fs/namespace.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index 781380945d78..1bb9f90a6523 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -6580,7 +6580,7 @@ bool current_chrooted(void) static bool mnt_already_visible(struct mnt_namespace *ns, const struct super_block *sb, - int *new_mnt_flags) + int *new_mnt_flags, bool foreign_ns) { int new_flags = *new_mnt_flags; struct mount *mnt; @@ -6606,11 +6606,16 @@ static bool mnt_already_visible(struct mnt_namespace *ns, continue; /* A local view of the mount flags */ - mnt_flags = mnt->mnt.mnt_flags; + mnt_flags = READ_ONCE(mnt->mnt.mnt_flags); /* Don't miss readonly hidden in the superblock flags */ if (sb_rdonly(mnt->mnt.mnt_sb)) mnt_flags |= MNT_LOCK_READONLY; + if (foreign_ns) { + if (mnt_flags & MNT_READONLY) + mnt_flags |= MNT_LOCK_READONLY; + mnt_flags |= MNT_LOCK_ATIME; + } /* Verify the mount flags are equal to or more permissive * than the proposed new mount. @@ -6629,7 +6634,7 @@ static bool mnt_already_visible(struct mnt_namespace *ns, list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) { struct inode *inode = child->mnt_mountpoint->d_inode; /* Only worry about locked mounts */ - if (!(child->mnt.mnt_flags & MNT_LOCKED)) + if (!foreign_ns && !(READ_ONCE(child->mnt.mnt_flags) & MNT_LOCKED)) continue; /* Is the directory permanently empty? */ if (!is_empty_dir_inode(inode)) @@ -6649,14 +6654,19 @@ static bool mount_too_revealing(const struct super_block *sb, int *new_mnt_flags const unsigned long required_iflags = SB_I_NOEXEC | SB_I_NODEV; struct mnt_namespace *ns = current->nsproxy->mnt_ns; unsigned long s_iflags; - - if (ns->user_ns == &init_user_ns) - return false; + bool foreign_ns; /* Can this filesystem be too revealing? */ if (!(sb->s_type->fs_flags & FS_USERNS_MOUNT_RESTRICTED)) return false; + foreign_ns = !ns_capable_noaudit(ns->user_ns, CAP_SYS_ADMIN); + if (ns->user_ns == &init_user_ns && !foreign_ns) + return false; + + if (foreign_ns && current_chrooted()) + return true; + s_iflags = sb->s_iflags; if ((s_iflags & required_iflags) != required_iflags) { WARN_ONCE(1, "Expected s_iflags to contain 0x%lx\n", @@ -6671,7 +6681,7 @@ static bool mount_too_revealing(const struct super_block *sb, int *new_mnt_flags if (s_iflags & SB_I_RESTRICTED_VARIANT) return false; - return !mnt_already_visible(ns, sb, new_mnt_flags); + return !mnt_already_visible(ns, sb, new_mnt_flags, foreign_ns); } bool mnt_may_suid(struct vfsmount *mnt) -- 2.47.3