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=1796442884; b=GoYFSMM0hpntmOwRVb3s8FQERkLe7A37zkYDD4vIr1lxROsL9Suyf2U6cZkdNG24q52q 8dKTFlH6TsAH2Dvm7tX8H32EDdbS/I3wc/f6Bbu9VievTAhbgRh5OrBO9TbKVj0bPYyKV u/JtqmXhQf7DWGZpajv4ZmOj3dPE7hYPVIN3xQZsK8YkLZ0siy5/giGL/abqBPPSp8srQ rFLH4SCx0LwHaY3pMGYim9237+CEjgYdGBJU5odBK8QqWy2bNRYyxhDiIQHMT4O2JJOjS 7EDVhzGtaMcKRF3WgAs9PWo4KbDG9uuHG2u+rmX4dfkC3c3gtexor8pDZXG3wQta3NQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796442884; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=fELN1LLhFJDvOJEhUdYCXi7lE3+RmqV3nfrh50puf+M=; b=JOlsy+8yvaXqGRtshh5xTcXDSTH4B3kNRGusNt/xEvzq2nM3DuLnGBSy4J3p3TeWrzr2 5zzu+rz1sH9INm5xSVCVNthll/u2on7K5Xy0t3seAVhEteFJCjvrrbAHIwItabcYXDFrs UPOS/tfzspBxPA2OBPAQ0rzI1gZMAbTsLGpcaLm0znHfYa6PhFUzQ7Z8kSxMO/inJMIsc 04MxInxvSGtQrS6vD415BkiAlX62blXv6exAArMHZyiFsPuZ7d2Ams9AI9MPJNoZqcFLx QG4N7xXBbnoWF36vw6fePJzc28TeRJMp2Ry3Xdp8UN3YtHrSm8TF4WtetzROTWXSdCA== 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=lanB6sKY; 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 ESMTPS id E2614606A32F; Sat, 5 Dec 2026 03:54:43 +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 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-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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