From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3B8A0606A322 for ; Sat, 5 Dec 2026 03:54:48 +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=lanB6sKY Received: by kanga.kvack.org (Postfix) id 15C776B05B5; Fri, 4 Dec 2026 22:54:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1344E6B05B7; Fri, 4 Dec 2026 22:54:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04A006B05BD; Fri, 4 Dec 2026 22:54:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C609C6B05B5 for ; Fri, 4 Dec 2026 22:54:46 -0500 (EST) Received: from smtpin05.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 57E0016029B for ; Sat, 5 Dec 2026 03:54:46 +0000 (UTC) X-FDA: 85508562972.05.8871239 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf23.hostedemail.com (Postfix) with ESMTP id A3117140006 for ; Sat, 5 Dec 2026 03:54:44 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=lanB6sKY; spf=pass (imf23.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796442884; b=FWkbPoepebCO8+uPrPYGRetf5TrdYYGxfeG6z/v2QCfOAiOp/sHt2PaIsD0/TzBy+BhVql rvvxE5Y+IHXvyaweJKoEsTNkrRw0+jrglrKC5IpBO20uX7bRG26Vq6ivft7YwO+qK9l+Wi cyR9Dcyy7qcqFGLDlNhKThEhNvqH+WY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796442884; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fELN1LLhFJDvOJEhUdYCXi7lE3+RmqV3nfrh50puf+M=; b=mxPBEdnOM+bw1Uk+gtsE4LEI9jEfwIayuUUD1cDK+KlqBTU3KYGEsDLz5OfN3X12pHV6m0 W1nEB16Klvtdz/azofkKlbfqnHf+ahpgykoE2k8oY1jOOxEGrOtXLv+xx0rdieTOAUFL4E L144G1bb/BlObypMaw95zyqtpSA2zuY= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=lanB6sKY; spf=pass (imf23.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id C6FF444014; Sat, 5 Dec 2026 03:54:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D922E1F0092B; Sat, 5 Dec 2026 03:54:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796442883; bh=fELN1LLhFJDvOJEhUdYCXi7lE3+RmqV3nfrh50puf+M=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=lanB6sKYUi4HZnX6Q4/r3kXQkdm37sDpv3ale3UDARePy98+bwINvyvYlQ7aNNCDw /W1h11WO5U5bH6wjD/dIJ095QZcZyywOT2p+E3/K78vRuBK9I3OaitnL1/+euLMOxj ltnzXZXH5GbC/+B01iuXctMz+tratTgdv0MuU9CRIwkzw1aD5u059cNGofbHkjkejP qisuDpQ0R4HOJYk3D+4ky1kXaFu2iqRRWvPm7suLh39r5F11MvwFR8f9kMcQMryEDd EP1H1CV3fn7HT6LTt9wU1U41XbAsw1KmbdAgRPEy8bcLG+ZNjfHVZnR5aifvX9Qs5q /471jQWJGvrzw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH v10 04/28] mount: Enforce mount_too_revealing() for foreign mntns Reply-To: sashiko-reviews@lists.linux.dev To: "Jarkko Sakkinen" Cc: bpf@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?b?R8O8bnRoZXIgTm9hY2s=?= , "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?b?TWlja2HDq2wgU2FsYcO8bg==?= , "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" In-Reply-To: <20261205032633.1702772-5-jarkko@kernel.org> References: <20261205032633.1702772-1-jarkko@kernel.org> <20261205032633.1702772-5-jarkko@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 03:54:40 +0000 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: A3117140006 X-Rspam-User: X-Stat-Signature: dcgtdqt43p3s6h738bcopy1tgkdeqqt8 X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796442884-989365 X-HE-Meta: U2FsdGVkX1/KdQN2wbX0Uaj/k5fz0pQBRqhf8ZeYyX5vUZeHKBN4mQlDURubFzOZdT2BZ+sK9L9edNSTvmCaxMdi8A8X22sbblET8oD8Kt91w2DMfYxuETTOtGQrrDe6YMrTnxsE9X68SC/bW78m+jEY83epNotlxD6MsbKOvKDo3lw3CQwaai5IqCTVhZKtx2DU2yKyg+R6HLOay8WwqRNruGByEZV2cjXSsqH1h0L1/7u4Lzry9GaN7lisamNbpmocn1Nu4gS4MJm8Rs2hBiursv6RlwNFLQA7vzx8xmJJ8HgyY5Z9LbtXxp91iL0CHxB8323mLDh4fxgMQKdz1HWPfRxlqsKR/NMwvQo5IOTyHYo6eZ60UX0JqR0FrvW9rVOz0iyR0lJQwMo6g99V/oSAkKed1sORib6SawrFYvH7SrlwSQc6FVz0lpmc+nTKt+E0FOgJZVi96u1p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oN4pnHKR1V/vmUYlw5AFatX36Bsk3civO95oaqZA3uT9ZNHP+nqLS4kE/gvc/Dl8MavC63Zzoc/iRu7V93UEZ5o59Jrd0Sf4zmJPhT5AHKO/3CaramTeZmz/jicur5Zw72ZV/uZyWMe53n9qeCGhHGFFmbpvkEcc5p0m5sbe8x/35ZIBOWhkKcGZANmO9OlsjgNhyy+W4ysid3CmhpAxisfmUok+DL0lpS0tBdr957hwuTgBO7ysehLzkfioblrkYwc31wnYK/ljXkRZzCLRyVHYHrXqisqi2rtW0spHr4ylMPREhy4YyecSr64uMscCqDPhKexFq3QGDr6Bad30TQ5j6NPlc7fku6CkRK1u1dss7M/eWZZnBhBEY/WwSvg91UNDLfiEz7L/9dB1ymxxN0TQSg2D1UKp6VF/mA== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] mount: mnt_already_visible() reads mnt_flags without mount_lock - [Low] mount: missing Fixes trailer for FSMOUNT_NAMESPACE visibility bypass fix -- commit 15f517d9a30829b2bc8ccbdefdaf58dadfccfadf Author: Jarkko Sakkinen > mount: Enforce mount_too_revealing() for foreign mntns > > 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 [Severity: Low] This fixes a visibility-check bypass introduced when fsmount() exempted FSMOUNT_NAMESPACE from may_mount(). Should this include: Fixes: 5e8969bd1927 ("mount: add FSMOUNT_NAMESPACE") > diff --git a/fs/namespace.c b/fs/namespace.c > index 781380945d784..1bb9f90a65239 100644 > --- a/fs/namespace.c > +++ b/fs/namespace.c [ ... ] > @@ -6606,11 +6606,16 @@ static bool mnt_already_visible(struct mnt_namesp= ace *ns, > continue; > =20 > /* A local view of the mount flags */ > - mnt_flags =3D mnt->mnt.mnt_flags; > + mnt_flags =3D READ_ONCE(mnt->mnt.mnt_flags); > =20 > /* Don't miss readonly hidden in the superblock flags */ > if (sb_rdonly(mnt->mnt.mnt_sb)) > mnt_flags |=3D MNT_LOCK_READONLY; > + if (foreign_ns) { > + if (mnt_flags & MNT_READONLY) > + mnt_flags |=3D MNT_LOCK_READONLY; > + mnt_flags |=3D MNT_LOCK_ATIME; > + } > =20 > /* 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_namespac= e *ns, > list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) { > struct inode *inode =3D 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)) [Severity: Medium] Can mnt_already_visible() race with concurrent remounts when reading mnt->mnt.mnt_flags and child->mnt.mnt_flags without mount_lock? mnt_already_visible() holds only namespace_shared, whereas do_reconfigure_mnt() and do_remount() update mnt->mnt.mnt_flags under lock_mount_hash() using plain stores in change_mount_ro_state(), set_mount_attributes(), and mnt_make_readonly(). In particular, do_reconfigure_mnt() clears MNT_READONLY before updating MNT_ATIME_MASK: CPU0 (fsmount FSMOUNT_NAMESPACE) CPU1 (MS_REMOUNT | MS_BIND) mnt_already_visible(..., true) do_reconfigure_mnt() guard(namespace_shared)() lock_mount_hash() change_mount_ro_state() mnt_flags &=3D ~MNT_READONLY READ_ONCE(mnt->mnt.mnt_flags) <-- sees read-write + old atime set_mount_attributes() mnt_flags =3D mnt_flags unlock_mount_hash() Because foreign_ns now derives MNT_LOCK_READONLY and MNT_LOCK_ATIME from unlocked flags, a concurrent unprivileged fsmount() caller can observe that transient read-write plus old-atime state and mount proc or sysfs with an atime policy disallowed both before and after the remount. Both READ_ONCE() loads also trigger a KCSAN data race against those plain stores. Holding mount_lock (for example with guard(mount_locked_reader)()) in mnt_already_visible() would serialize against lock_mount_hash() and prevent both the torn update and the data race. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205032633.1702= 772-1-jarkko@kernel.org?part=3D4