From mboxrd@z Thu Jan 1 00:00:00 1970 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 28F764A4F04 for ; Tue, 13 Oct 2026 23:04:19 +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=1791932661; cv=none; b=ep80eBIx/kitWAREWzZId15KhdNLMkryrx3nDfmNCBfrDlesrrA1xATTw1hX3yq0n9G+8zZlgW35SpT6qmGnL5Q7qLF3KMBU3rF21g12HxX9S5iIN7n5Sn9UAe3V9HuqBOj7G2Tbi1/Adw0wD31QSMqN6FCl6wPB9rxCgoQp8ig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791932661; c=relaxed/simple; bh=e4mv65ZTz92dGckJMFBeQXXM66LYL8r2iUOEEhsNcCk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dGylSgrjPlYqFEW1HUMTPXAK919XH4bXiZ4jkhfyO6eCkzAcgMoskgoT/XJmdFIrVi4+64oFqzlewxrvvWq+pqq1T9NRneeLUw0Ij7UN/k22V7nq9j+puP/JJ5Tj8GP2YAYzDqFr20lt/xXV6mK1f55vHvUQU/sUMWj1kZ7tPX0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iZGN+wCv; 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="iZGN+wCv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5433D1F000FF; Tue, 13 Oct 2026 23:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1791932659; bh=wgSTFME8wCbtsDD6iy97+jq0HP3toFBnGcwPU/giGSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iZGN+wCvxfIjIpcL0S3zgze18XX3+GdvpUWXUXlBKK3423990wmX3PQImwBxIpmJM A0OA7BjwLtZVGwrER5o4wSMXLfuJN9WVG4Wv4k/KMalhoCiXTGYvFlgbnHG1qilcRM /cvjLzM1L/Gj0Ur7FB4Eje5Jz/xhXKlvwNXDzhGh1PA9GhE3DaaBh+QC6XFBDhGtrp HAK3KtNoBbmlaQ3tsc3lCFxryvoPRERdFKqxFJZXC9h6elFoKyXGok6oePY0IdeQDm YA6YOoNwY+NoHTqgMrvLTX0AZMAKsEdxueWXwW6odWjgDHFJwHCqMnsXcdBzoTT967 XYavZp3TeQxbg== From: Sasha Levin To: stable@vger.kernel.org Cc: Christian Brauner , Sasha Levin Subject: [PATCH 5.15.y] namespace: don't copy an unmounted mount tree Date: Tue, 13 Oct 2026 19:04:17 -0400 Message-ID: <20261013230334.1057236-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026101201-arrogance-designer-e9e2@gregkh> References: <2026101201-arrogance-designer-e9e2@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 inline mount validation in __do_loopback() ] 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 ff8d16a3eeb2d..ca8108097a2aa 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2384,6 +2384,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