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=1793209190; b=nT2ndoj8qsuwfA6r+2kTqrVy3n+SSQcEywurXBKvUKoxLaVrMVDcbik8H9sVWQ4kq0GW +UK+IMZpvnwOFk12R4H6aReQjLS1TH6dFmCt4yJ/d8QB6FurXiAsqKFsL1FMnaNxuNVGo AXJnPLpyU5PhPXgZWzNB9gIBE7HCEk+a67wpvh2eG2ElrR9JsShG3jrUCyzwAqKcaHFOA gRJxq+75gI7uaB3x9WBC1lqp64Y4Lbr0VB8GZYT5XVBISxsdzDinJdzG9U5rPxyFHIWrn zG2eqTxMv+M+de3/MdG3ZFxS9l7YgKsAry6NJiuGnRh6BIH2fKufj4ewK7m80dCJIAA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793209190; 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=LytmBH6G+t0LMx/rNUWzB1jjFgV/4Rcx8zfFrXASfow=; b=Kljl9DFbqzjk1X2XckR7d1VKk2olpE6uL53UxM2PBBjggROdnCIQzb2pgiqTevF0NqkR 4QbUEb6TLoBLWAaUaNC/+O+52f8HLZBaewU4p/OMreiXqxnegKnXOURk8IqY/rT7gsiTX X/wqSbOSLHEuxA1+WoI5nJcxHbOmTzsUzccx9otASrOt5YkevKUz0EA7fV/XDDTJtxJCA uN2VIcP2PMJlFsPcZpM6S5QxxKP5RuSop5kcGpqAnKkzIVQ78Q7OZWairNUiTsmTeZqwa kttZ+oI7rUGD2fVRxDsUMkyJ6vtedonyIVuHOy177Bzj6pzT/QovQEElV1r/mGxz+LA== 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=gmkprsNF; 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 8DBBB606A33D; Wed, 28 Oct 2026 17:39:50 +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=gmkprsNF Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBC631F031E5; Wed, 28 Oct 2026 17:39:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793209190; bh=LytmBH6G+t0LMx/rNUWzB1jjFgV/4Rcx8zfFrXASfow=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gmkprsNFiSuOxZl8i6XtaglFTuCu44F6Dls6wdgR2eB9PBHc+PFwE34LKrVnF4+r6 TzC2QAjvECqR5cRFrDCEj7SzI2M9DpnVHIZQGy4enIfbpuewJuUlEZkF/F3To/DY+V yhTKgkgqAXjbtYnAB1DkB9ujOZa6Q8sa2EQrywQU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Christian Brauner (Amutable)" , Sasha Levin Subject: [PATCH 5.10 385/516] namespace: dont inherit MNT_UMOUNT in clone_mnt() Date: Wed, 28 Oct 2026 17:58:57 +0100 Message-ID: <20261028170012.602590598@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170003.522232767@linuxfoundation.org> References: <20261028170003.522232767@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 5.10-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 MNT_UMOUNT filtering to the explicit flag 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 769f22c0bc66d..a87eb7fdc9838 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -1057,7 +1057,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_sb = sb; @@ -1492,6 +1492,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 aaf343b38671c..c03773e480193 100644 --- a/include/linux/mount.h +++ b/include/linux/mount.h @@ -52,7 +52,7 @@ struct fs_context; #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