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=1796094645; b=LRvNm2lhQJwNWA6Auh9QXtpnmb6QXpB9eAs1Z0gP36JA6RBwKAweZo+EvRYXAN9qxV8S AVVpxOCY90acIvdY6WdL6mfimYAX0fKNfJAeh7UMQo1lcRfD0dHyshRUjUioBwc7fbXrf SKpRKAJzbGHZ4XgICE+g9yhDmK08G+ao8kGt3BmkMA05n+5ZR3lch+2TtBa12BtOmp6Zd yOMhSzHoV0O32x87tmU8wkt5FKAzBMEyde+fLCePV3jhjyDvijhYSMCuEZsJ6HxismJn2 Pv3RqRP+Rj5csudYJzBZBi+ounb+D7AyaWgXKeSEbZSh2zuPMNGfgXukm589IBnZ0Fg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796094645; 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=KCi23uLNqLS5ASgDWdOomBqjFZy/am32pV5iLh03MhNAnDRtSXBynIFMiJ1RQcJp2/jo +uAWivFhwPPDa9uDn9nedJWqOF98wOGGIKanAfdfcJV+AFm27ZZoQ5m+g0iJ35Z08mV/v T/luo7vTtF/nU8kxBUKWtY4MIe55I214gF8jGJ/6caaoNLvg4BKu/WXHs3ZMPDperNsr1 yusWNq2eHpRFYFEHlp5WmxS/mEDkELGGOMJZoY03/3CGJHGqOWNqdhpBeg5A6Iog3mTG8 am06V++UC0rwaaeg7ac9LQUlJ1iR0PljtXHHcZsOL9YS1ANvx/psba2rChhQELHg31g== 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=XXszRNvm; 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 264AD606A327; Tue, 1 Dec 2026 03:10:44 +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=XXszRNvm Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 0B09F1F00897; Tue, 1 Dec 2026 03:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796094644; bh=l3BxF7eKc8H9WX2SeKI00rPkbSvVT1UJBee/DhqmTQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XXszRNvmIKfzAJaQoY5Ohm2AAqy5t8chnJ4CBgmEnDENw/X5IwRBMMJ71mLp2d2Ry eR1DHeqUIlRAK7EURIWuiK3u8N8f00K31xWagB+yFRmFvDFkFObKxG6+uCflBZHw/9 boHwXVRrfM+4wOyEljrugemmFDDTg8jKPSahewDSCvxPoLa2A1GZ6TyxwUSOsmhJUB 3gDYcHeoh+OfwgOlAvON4mvJX6MwXb8NS5vhane8DWw4CBRjrT33ekgTHTKh6+3WM1 C8ns6qUucF9pmWRTRLngNdcQmizMY80Q1mLfl7LqAd/7Jlmg3Y0oyLJH3c0yT3blvE Aby1ycIc5DDiQ== 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 v9 05/29] mount: Enforce mount_too_revealing() for foreign mntns Date: Tue, 1 Dec 2026 05:09:37 +0200 Message-ID: <20261201031002.593830-6-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201031002.593830-1-jarkko@kernel.org> References: <20261201031002.593830-1-jarkko@kernel.org> X-Mailing-List: bpf@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