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=1793213654; b=Mxwle6Vign6ylfDJVQUqJW9Zq1bTUNdFc8izopwQU1OVjWE/q/otgt1gVHIKxzW9OyP7 hv80hgC/kQaUKDQidhTE44+pOn9pEZLt64QAhixe3+twI3vSisXMcmKgTqbOGDAqCPdw+ et+SfkTtfoHpivNTAPTVEQzqjUJtKW9xev80eHszO4BQ++J93JcHFbLhvQxMDs1RAg/AY fJIfaDsC0nXVAoIGTdl9yGKy4BKWcrn8fHsBUg1VnU9dMPQ0kBYAWi+uzneOozHznk6OB /N1XC4kCTTwjyuE1D8Eq1gQffH7kr20kJjhK+HVGuk+YPvynbiJhM3u8WaAZoKhqOeQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793213654; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=L/ix8tCXcBYDSkQKjkfg13FI8vfzbgcHVDatID4t884=; b=zEABQrPmgHedWl8gBFarQ3sMKcre8SzjGTrX/+jVAKWLu09uRa+KVJKVMwTKyIhpASN8 QtpmwD2osuJYC8p8l3iDhw7l6ztOR2+xeBvdrzKOOTLxjbjfRajsXX+vE2SgYncpq5oTH 7fdOXJNrlulCXuGHQo4/Wxr/j7zWIRYirPBDCQhzZcTXaqS9qzfa0lH/osYvknQ3l6JKj AhZZwYOJOeSpzF5gdShCA4nWa/OfkcZEgECU/5qhzw5brnT/WdT3XQMmKHxQaYUzy7F1W VXUl91Gk4LqGMOVzPg7mATkMgjX3vBtrVXVny1O3MU9hTKo5QnxbpoCQQ3KBXb3qY6w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=atjUsH64; 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 1818D606A31C; Wed, 28 Oct 2026 18:54:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=atjUsH64 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 656281F01825; Wed, 28 Oct 2026 18:54:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793213653; bh=L/ix8tCXcBYDSkQKjkfg13FI8vfzbgcHVDatID4t884=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=atjUsH64bC4E/ugMcXrgHYdEyKfLV1hbQXudzEEih+c7GuZ+Ag/UFhyn8QuwJMMX2 5mAoHzwY8+IXzqpR6K4wLoQh/mAVjOJOCnTn/sOyVq2Pj6PbJ90EKG/CA3hRPNVW7z DQSi8CL015bAQoQzxaRYfKEPOY1hBpJ0qpBwHVZA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Christian Brauner (Amutable)" , Sasha Levin Subject: [PATCH 6.1 0528/1887] namespace: dont inherit MNT_UMOUNT in clone_mnt() Date: Wed, 28 Oct 2026 17:43:44 +0100 Message-ID: <20261028170511.353287577@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christian Brauner [ Upstream commit e2c6d326216642011da318b9edfd5d57ebd5a56f ] MNT_UMOUNT gets raised on a mount that umount_tree() or umount_one() has taken out of its namespace. It's never cleared. __detach_mounts() unhooks a mount that carries it instead of unmounting it. disconnect_mount() lets an unmounted child stay attached only if its parent carries it. propagate_umount() takes it as the sign that a mount is going to be unmounted when it decides what else can be unmounted, where a chain of locked mounts ends and where a for reparenting an overmount. clone_mnt() copies the flags of the source and only masks MNT_INTERNAL_FLAGS which doesn't include MNT_UMOUNT. A mount that was lazily unmounted but is kept alive by a file descriptor can still be copied when its root is an nsfs or pidfs file because may_copy_tree() accepts those before checking whether the source is mounted at all: mount --bind /proc/self/ns/net /tmp/x exec 3< /tmp/x umount -l /tmp/x mount --bind /proc/self/fd/3 /tmp/y The mount on /tmp/y is attached to the caller's namespace with MNT_UMOUNT already set and every copy of it inherits the flag again. That causes a number of bugs: - Unlink its mountpoint from a mount namespace where it isn't one. __detach_mounts() takes it for a mount that was unmounted earlier, unhooks it from its parent and drops the reference the namespace holds on it. It stays in the namespace with one reference too few and as its own parent, so it can't be unmounted through the file descriptor anymore and the namespace never finds it again. When the namespace goes away it's leaked and points to a freed struct mnt_namespace that may_change_propagation() and anon_ns_root() read on the next propagation change or mount_setattr() through the file descriptor. - Make it shared and unmount a peer. trace_transfers() follows the flag from the peer into it and strips it from its peer group. - Let a propagated umount reach it. gather_candidates() marks it with T_UMOUNT_CANDIDATE but never puts it on the candidate list, so the mark is never cleared and every later propagated umount skips it. If it's the parent of a locked mount handle_locked() takes it as the cutoff and commits the locked child that should have stayed and disconnect_mount() leaves that child attached to it, unmounted under a mounted parent, which is what disconnect_mount() exists to prevent. When the namespace goes away umount_tree() visits the child a second time. And once __detach_mounts() has made it its own parent reparent() never finds the end of the chain of unmounted parents. A clone is a new mount that has never been unmounted. Add MNT_UMOUNT to MNT_INTERNAL_FLAGS so clone_mnt() never copies it. And warn when umount_tree() reaches a mount that already has it set. Fixes: 590ce4bcbfb4 ("mnt: Add MNT_UMOUNT flag") Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260926-work-mount-fixes-2-v1-3-f357abf3d17b@kernel.org Signed-off-by: Christian Brauner (Amutable) [ sashal: adapted mount-flag handling to the explicit flag-clearing mask in clone_mnt() ] Signed-off-by: Sasha Levin --- fs/namespace.c | 4 +++- include/linux/mount.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index 42ecf070b6f76..2492d5286cef6 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -1122,7 +1122,7 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root, } mnt->mnt.mnt_flags = old->mnt.mnt_flags; - mnt->mnt.mnt_flags &= ~(MNT_WRITE_HOLD|MNT_MARKED|MNT_INTERNAL); + mnt->mnt.mnt_flags &= ~(MNT_WRITE_HOLD|MNT_MARKED|MNT_INTERNAL|MNT_UMOUNT); atomic_inc(&sb->s_active); mnt->mnt.mnt_userns = mnt_user_ns(&old->mnt); @@ -1561,6 +1561,8 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how) /* Gather the mounts to umount */ for (p = mnt; p; p = next_mnt(p, mnt)) { + /* A mount is unmounted once. */ + WARN_ON_ONCE(p->mnt.mnt_flags & MNT_UMOUNT); p->mnt.mnt_flags |= MNT_UMOUNT; list_move(&p->mnt_list, &tmp_list); } diff --git a/include/linux/mount.h b/include/linux/mount.h index 55a4abaf67155..76c21958e8426 100644 --- a/include/linux/mount.h +++ b/include/linux/mount.h @@ -50,7 +50,7 @@ struct path; #define MNT_INTERNAL_FLAGS (MNT_SHARED | MNT_WRITE_HOLD | MNT_INTERNAL | \ MNT_DOOMED | MNT_SYNC_UMOUNT | MNT_MARKED | \ - MNT_CURSOR) + MNT_CURSOR | MNT_UMOUNT) #define MNT_INTERNAL 0x4000 -- 2.53.0