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 6D49D606A33C for ; Sat, 5 Dec 2026 04:05:31 +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 kanga.kvack.org (Postfix) id 654D76B05D2; Fri, 4 Dec 2026 23:05:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 62BBD6B05D3; Fri, 4 Dec 2026 23:05:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5696D6B05D4; Fri, 4 Dec 2026 23:05:20 -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 DC1736B05D2 for ; Fri, 4 Dec 2026 23:05:19 -0500 (EST) Received: from smtpin29.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6AA471C36EE for ; Sat, 5 Dec 2026 04:05:19 +0000 (UTC) X-FDA: 85508589558.29.F509A62 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf29.hostedemail.com (Postfix) with ESMTP id B158412000E for ; Sat, 5 Dec 2026 04:05:17 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=RVMeCsst; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796443517; b=CnTQ/7vU+qUBv18nN/IO2e+7nXKvQ1Azji9OSOLFtkbzR3ZPIkGX9vOzhCpgvvgE82W28j 8DXJW8XGXzQBWymufTtPx+1IIlr8ur5p8sUnLMUtcbE5n5awjdg+DCU7/TKIBVKZ+siiTh CSd1Wp4iQgCj/ZKvsdqCQZRvlSL7dws= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796443517; 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=lDKyQ22p65dCqO9PXKh/SpJ+hE0MNQ+KJ4QpDdPEyfo=; b=om7Ax/oESwEb31MANb0fFxnHY8V9R5Uysw1YlGKbwpfRvMhWDe6atp9BSXmvckCZsUI8eS pfgSVJV8WmUgecqEfDA7zIhnA+/aTzZLEGdvRnNc6nXofW2rCsQklVOq929S4Bbh5fII7L fAIR5jw8i1jzr/iqeGs7Izt1WbvwHzo= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=RVMeCsst; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id E86B745A70; Sat, 5 Dec 2026 04:05:16 +0000 (UTC) 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-Rspamd-Server: rspam11 X-Rspam-User: X-Stat-Signature: mjxujpki6b7onpst9gh4j7grkojm4ipo X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Queue-Id: B158412000E X-HE-Tag: 1796443517-518939 X-HE-Meta: U2FsdGVkX1/3acxfgHY8S7ON+ZtHLwldY0YjNY0r+Wz3z351nagx5am42pV5F6+Sig523HDrBOXCHFAhSkn9zOYS9K3aEMbo6bVSWRcuNFTJA4WERwhRXxTbeH95ObGpulUF/j458oocc60V5ly8yzkcGq/EUqs3z3PUCtHlbjKctayeR1AzGGVUL3a0zjuTJMUOeOQccm2jMdhqbGHcivvU4Hm0Lurjeb21J4YjJiMx+T19NPvPQitCqgbQlrnckCH9GGAhNvLSeloL+oOrDE+MWyA2Y4I5QDQVxXoUCgDMhu96a5/TxTDfGKWN6FpJgu38AjnMrLYJv1/qCc6cp2SnPJ7RqaFPErdhVsm3HLQ6r7EXWjrRODmc4HAX/+OvqfgG0syNoXV/0cx9QBScdpIie7NFPPQBFAUUJJYH+UKA+ZunJEWu/IjBuOhuzpuL0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LgN4p5WFbeSVtc5+2roUpqlq5hYDrY9Ek3fnFaVKsLG92I8RvUMX4xw6d0V5cqeXH6ytTqVd072l1+nfvlWhz4KdkKJZmDerM0/jyJDXCld8IQbAQKoLYHlF3fQubmlP+3DMxUgDmzh6Zn94o0UkQ2Oo9JHsw5cMAS6rmfHbK2DROzVHrueh0LgsFehn+jFFvOsuryc2ELgJvW7MHogtVd8kUHRV1bM3FFBAruDOu75bY0DWvsRdUkrkOR1d3gjzTyDSxcExHhp8TxSXRdX3ht7Diir0ExPU/rkQ4jAde6PsPOvCWV8MLqvFxE4mV3FSu3qua59lwBWB0ur1byf80dAT+mZ9BoH+CJJ/5+y78Sn0v/v8Za/kVaMuBRl/oxQEigpksfg2Htdae82hWUFdzg== 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 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