Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B05975372EC for ; Tue, 13 Oct 2026 18:52:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791917553; cv=none; b=IxuvOi0wuKjB+FC36iALTc7lHSk2u7hjZBNMVmVw3crzxtr/hgV9eYQQv5B6xAfc6ocoAUMPZOueBuTNtx+bsHldkRt5pPJRRuCLoHx738VNi3jmDqnxj/5QrCT8Au+zQyAu+80C+skFfZGl88UzXAuTxlG0/9meDW/8ge9p4II= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791917553; c=relaxed/simple; bh=5XdPylDRDaT+x5t0GGjZLctpGaYwZiDzGoNkusNE2jE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KocQo1hajhARxEamU1GyindETVotPJbN/vLqEiV3lNmnouXuE4nxFo8WSa7xAfLOVLtFgT4vTNhQro8H/t6pdTlDe6oPRNKuhKn98M1GeZBNBm4wHskUvOlOBtbnGqChDrOQStJH7owzrLIIHD0A4eSNVa6B6Xl9zhYgxAz6gtc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UUoNVYzs; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UUoNVYzs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E367E1F000FF; Tue, 13 Oct 2026 18:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1791917552; bh=Q7ZCPV200IiAeJzUqgXR+XFLqeB8zOOdpMXxWAsSmg8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UUoNVYzsl144OIgdzfBgyZtAMk4KSfh7WQwk9JMwD+eKKXg25G6w6InJ8KPJRkk3f yLkk5ExI24atYgYSKzQSeyGxR3vqPij3vl6WIUhlCmOMyLkTZ+GEkTHrHO38I1domj sQ5eodDxmeiFoUkllh3LcAJRoxzzzfSQbZqK8Zz9pnhTjm8E3D+tXmJbohhYkd3YFp o9ZwLFspeAcK8GIw5Vr3wSA9ebyDTQ7B/cED23dIqR61soxWJV7weGcp2+Mn8U/Otx lvR1/fPzPRJL69zXL5kWhjN5jC9VitUjiidqQ5/2CCZxj4tMcK0PsEVUd5ihMjCT2f gsBxrR/5S/Llg== From: Sasha Levin To: stable@vger.kernel.org Cc: Christian Brauner , Sasha Levin Subject: [PATCH 6.6.y] namespace: don't copy an unmounted mount tree Date: Tue, 13 Oct 2026 14:52:30 -0400 Message-ID: <20261013185159.650572-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026101247-wagon-grimacing-e886@gregkh> References: <2026101247-wagon-grimacing-e886@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Christian Brauner [ Upstream commit 8bacbf6be959973b28b691713a872c12eae69eec ] may_copy_tree() accepts a mount whose root is an nsfs or pidfs file before it checks whether that mount is mounted. This exception exists for nsfs and pidfs mounts. They are part of no mount namespace so neither check_mnt() nor is_mounted() would let them through and bind-mounting a nsfsfd or a pidfd wouldn't work. Problem is that exception also admits a bind mount of such a file when it was lazily unmounted and is only kept alive by a file descriptor: mount --bind /proc/self/ns/net /tmp/x exec 3< /tmp/x umount -l /tmp/x mount --rbind /proc/self/fd/3 /tmp/y With MS_REC or AT_RECURSIVE copy_tree() doesn't stop at the unmounted mount. It copies every mount that stayed attached to it as well. So if you have a bunch of overmounts over the nsfsfd or the pidfd the whole unmounted stack is copied. That's a bug. So refuse to walk an unmounted tree. Copying its root alone stays possible. So a bind mount of a namespace that is gone can still be recreated from a file descriptor on the old one. The file descriptor pins that mount and its root and __has_locked_children() only reads the direct children which don't leave the parent's list without namespace_sem. The internal mounts carry MNT_NS_INTERNAL instead of NULL and are still walked. Copying an unmounted tree recursively fails with EINVAL. Fixes: e149ed2b805f ("take the targets of /proc/*/ns/* symlinks to separate fs") Fixes: ef4144ac2dec ("pidfs: allow bind-mounts") Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260926-work-mount-fixes-2-v1-4-f357abf3d17b@kernel.org Signed-off-by: Christian Brauner (Amutable) [ sashal: Adjusted context for existing inline permission checks and has_locked_children(). ] Signed-off-by: Sasha Levin --- fs/namespace.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/namespace.c b/fs/namespace.c index 3311e4edbc734..cb082885b721d 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2614,6 +2614,9 @@ static struct mount *__do_loopback(struct path *old_path, int recurse) if (!check_mnt(old) && old_path->dentry->d_op != &ns_dentry_operations) return mnt; + if (recurse && !old->mnt_ns) + return ERR_PTR(-EINVAL); + if (!recurse && has_locked_children(old, old_path->dentry)) return mnt; -- 2.53.0