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=1796443517; b=Id4NblI+Gsm498cUgvM21q8yeLK8hKsQWntTdxsB1EgC9LgWAddlL/r8ewOh/GfXzav2 tl0l7Nmy5cBafkKDYCM/d1HM0mtBhFPUg5OtNCmfPuZMabh6I5L2b1LSckR/AKQ0X9v+1 M/wF8CPCEUwnswZ6clYT+6+aHZqYIFPd/1j8KmeuclGMBIz0puLAWVBTxLl/O2jT98gs3 xqm+FBLazs1ZpMGJj0NeNvQv8U8tkIg4y/2VWxqvtPUlPZ0wlBsgZvEasDEFRLMfHQ3Va K+iRAqjOZeFEY/P2dLFGTk5xc6eAS9buuXRfitVmVxE7L4KW36WhlKCDzbfwuqJkZaQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796443517; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=lDKyQ22p65dCqO9PXKh/SpJ+hE0MNQ+KJ4QpDdPEyfo=; b=DhsrUNVrNQL3cU2Tj1pJy9rFHEqZ6BoEDnBvE4GUPDT/yl+pqMVNJ28R3mTMNpghCwTi gviTINn8ogjxxUw5W6YzZPy28bw4pGCcSSZUW27JJe6Gv9MOyGnLLar2bQJuJFWSCNHDN aCjhaKdgQGQPobYmhQTPU8VZhGhevd0w6nuaFGuyPUpI56Hq+CSwGQzQCIBTZIjbTpFno vYzLxxGYhrf6CyYSyVh98Z92D5r63/MJzns9vPI3Kri8NatFvOD8DiFTeOBrgltcPkGKY sc95iwabi2VKTJtHSKYfagcB7wBYYZZO8On2J4R8aP+ntzEpO4ffs+XgLlH5KRkvy8w== 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=RVMeCsst; 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 332BB606A695; Sat, 5 Dec 2026 04:05:16 +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=RVMeCsst Received: by smtp.kernel.org (Postfix) with ESMTPSA id 689051F00936; Sat, 5 Dec 2026 04:05:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796443516; bh=lDKyQ22p65dCqO9PXKh/SpJ+hE0MNQ+KJ4QpDdPEyfo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=RVMeCsstnTCnHQUKjO9JVMYfMMlJchh/2uT0UuPOYBLlm9533fb3Vgbti8/lZtsA+ 2LI7oxUrLQkKvV1vYbGhRaaI2K4unj02apVHFpDn1smu/TknJDBVg6tCM/CP64Ljs4 jCecB4Aa5iRXnNLmmOzrqGLEpTYFPbTsUJYNnUa5vCQJkWmXRqfH3d+g/0uk8eftcd IJDAfclpOhg/n9XAdn33d8w8obU0eEvqO4bUhuNDxVv9qkSPMv9GlTFAM7A0e4f5Kb NGxy8Q0pSIfLf5iwuGZh1xcfXHM+Uj+Dq8LBLxD/hvQq4OcKwa0vdD16iB+QzkwXiB H0T+BS50Ueyig== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH v10 05/28] mount: Support MOVE_MOUNT_T_MNTNS in move_mount() 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-6-jarkko@kernel.org> References: <20261205032633.1702772-1-jarkko@kernel.org> <20261205032633.1702772-6-jarkko@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 04:05:14 +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 4 potential issues to consider: - [High] fs: attach_recursive_mnt() wrongly locks propagated secondary mount roots - [Medium] fs: move_mount_mntns() bypasses chroot without CAP_SYS_CHROOT or fs->root - [Medium] fs: do_move_mount() seq_origin check breaks cross-mntns detached sources - [Low] fs: move_mount_mntns() returns EINVAL instead of EFAULT for NULL to_pathname -- commit 1d692a9a5d165e51f86787f083ea069a8a04b467 Author: Jarkko Sakkinen mount: Support MOVE_MOUNT_T_MNTNS in move_mount() This commit adds the MOVE_MOUNT_T_MNTNS flag to move_mount() so detached anonymous mount trees can be attached into a target mount namespace nsfs file descriptor, either as its initial root or beneath its live root. > diff --git a/fs/namespace.c b/fs/namespace.c > index 1bb9f90a65239..45a7f9547c8e0 100644 > --- a/fs/namespace.c > +++ b/fs/namespace.c [ ... ] > @@ -2725,11 +2742,22 @@ static int attach_recursive_mnt(struct mount *sou= rce_mnt, > hlist_add_head(&source_mnt->mnt_hash, &tree_list); > =20 > hlist_for_each_entry_safe(child, n, &tree_list, mnt_hash) { > + struct user_namespace *child_user_ns =3D > + child->mnt_parent->mnt_ns->user_ns; > + bool cross_child_src =3D src_user_ns && > + !in_userns(child_user_ns, src_user_ns); > struct mount *q; > + > hlist_del_init(&child->mnt_hash); > - /* Notice when we are propagating across user namespaces */ > - if (child->mnt_parent->mnt_ns->user_ns !=3D user_ns) > + /* > + * Notice when we are propagating or attaching a foreign > + * source tree across user namespaces. > + */ > + if (child_user_ns !=3D user_ns || cross_child_src) { > lock_mnt_tree(child); > + if (cross_child_src && list_empty(&child->mnt_expire)) > + child->mnt.mnt_flags |=3D MNT_LOCKED; > + } [Severity: High] Should propagated secondary roots (child !=3D source_mnt) receive MNT_LOCKED here? When MOVE_MOUNT_T_MNTNS attaches a detached mount from init_user_ns onto a shared mount with a slave in a child user namespace, cross_child_src is true for the propagated secondary root. lock_mnt_tree() intentionally skips MNT_LOCKED on the root itself because the mountpoint is already visible the= re. Locking that root breaks umount() and other mount operations in the slave namespace with -EINVAL. If the master then lazily unmounts the shared pare= nt with MNT_DETACH, propagate_mount_unlock() never unlocks the secondary root,= so handle_locked() leaves it stranded and un-unmountable until the slave exits. [ ... ] > @@ -3792,7 +3823,30 @@ static int do_move_mount(const struct path *old_pa= th, > if (IS_ERR(mp.parent)) > return PTR_ERR(mp.parent); > =20 > - if (check_mnt(old)) { > + if (flags & MNT_TREE_MNTNS) { > + u64 seq; > + > + if (!anon_ns_root(old) || old->mnt_ns =3D=3D mp.parent->mnt_ns || > + mp.parent->mnt_ns !=3D target_mnt_ns) > + return -EINVAL; > + seq =3D old->mnt_ns->seq_origin; > + if (seq && seq !=3D target_mnt_ns->ns.ns_id && > + seq !=3D current->nsproxy->mnt_ns->ns.ns_id) > + return -EINVAL; [Severity: Medium] Does checking old->mnt_ns->seq_origin here unintentionally reject detached mounts handed over from a third mount namespace? get_detached_copy() records the creator's mount namespace ID in seq_origin = for every open_tree(OPEN_TREE_CLONE) descriptor. Standard move_mount() only checks seq_origin on an anonymous target via may_use_mount(), never on the detached source, so SCM_RIGHTS handover across namespaces works. With this check, a manager passing an open_tree(OPEN_TREE_CLONE) fd from namespace A into namespace C while running in namespace B gets -EINVAL, and this restriction is not documented. [ ... ] > @@ -4736,7 +4793,123 @@ static inline int vfs_move_mount(const struct pat= h *from_path, [ ... ] > +static int move_mount_mntns(int from_dfd, const char __user *from_pathna= me, > + int to_dfd, const char __user *to_pathname, > + unsigned int flags, enum mnt_tree_flags_t mflags) > +{ > + struct path from_path __free(path_put) =3D {}; > + struct path to_path __free(path_put) =3D {}; > + struct mnt_namespace *target_mnt_ns; > + unsigned int lflags; > + struct ns_common *ns; > + bool is_root; > + int ret; > + > + CLASS(filename_maybe_null, to_name)(to_pathname, AT_EMPTY_PATH); > + if (IS_ERR(to_name)) > + return PTR_ERR(to_name); > + if (!to_name) > + return -EINVAL; [Severity: Low] Will passing AT_EMPTY_PATH to filename_maybe_null() return -EINVAL instead = of -EFAULT when to_pathname is NULL? getname_maybe_null() returns NULL without faulting when AT_EMPTY_PATH is se= t, even though MOVE_MOUNT_T_MNTNS disallows MOVE_MOUNT_T_EMPTY_PATH. Using filename_flags(to_pathname, LOOKUP_EMPTY) and checking for an empty string would keep -EFAULT for NULL while returning -EINVAL for "". [ ... ] > + target_mnt_ns =3D to_mnt_ns(ns); > + if (is_anon_ns(target_mnt_ns)) > + return -EINVAL; > + if (!ns_capable(target_mnt_ns->user_ns, CAP_SYS_ADMIN)) > + return -EPERM; > + > + is_root =3D to_name->name[0] =3D=3D '/' && to_name->name[1] =3D=3D '\0'; > + if (is_root) { > + if (flags & MOVE_MOUNT_BENEATH) > + return -EINVAL; > + > + to_path.mnt =3D mntget(&target_mnt_ns->root->mnt); > + to_path.dentry =3D dget(target_mnt_ns->root->mnt.mnt_root); > + mflags |=3D MNT_TREE_MNTNS_INIT; > + } else { > + struct path mntns_root __free(path_put) =3D {}; > + > + if (to_name->name[0] =3D=3D '/') > + return -EINVAL; > + > + ret =3D mnt_ns_get_root(target_mnt_ns, &mntns_root); > + if (ret) > + return ret; [Severity: Medium] Can a chrooted process without CAP_SYS_CHROOT use this to bypass its chroot? move_mount_mntns() only checks CAP_SYS_ADMIN and always roots relative look= ups at mnt_ns_get_root(target_mnt_ns). A chrooted task with CAP_SYS_ADMIN in target_mnt_ns->user_ns can pass its own /proc/self/ns/mnt to probe paths and attach mounts outside current->fs->root. For comparison, mntns_install() requires CAP_SYS_CHROOT before resolving against mnt_ns->root, and grab_requested_root() uses get_fs_root() when targeting the caller's own mount namespace. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205032633.1702= 772-1-jarkko@kernel.org?part=3D5