From: Pavee Zheng Date: Sat, 05 Dec 2026 08:42:57 +0800 Subject: [PATCH] namespace: clear DCACHE_MOUNTED on live cant_mount dentries MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261205-patch-vfs-maybe-free-mountpoint-v1-1-3513519288ae@gmail.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yWNwQ6CMBBEf4Xs2VWoARN/xXDYlq2sgbZpC9EQ/ t2ihzm8yeTNBomjcIJ7tUHkVZJ4V6A5VWBGck9GGQqDqlXXqLrFQNmMuNqEM300o43MOPvF5eD FZVRNba/djWw3tFAsIbKV9+/h0f85LfrFJh/aY6EpMepIzoxHVdSXkjNNE+z7F5vYvhqhAAAA X-Change-ID: 20261205-patch-vfs-maybe-free-mountpoint-210f367af6d5 To: Christian Brauner , Alexander Viro Cc: Jan Kara , Alexander Mikhalitsyn , Aleksa Sarai , linux-fsdevel@vger.kernel.org, Pavee Zheng X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796431378; l=4952; i=pavee.zheng@gmail.com; s=20261203; h=from:subject:message-id; bh=RdROSWI1AGJGbdxaPI5mjjUqSnxSkHxSXgpSEr6Ivtw=; b=JCeCT2wlZJs3AZ3D7xZTW9sZqvX1jBPlB4hHhE4/w6/v2U01mgffejc4JKDWW4BgHbecI0Azc LWoPe0oat50A3xf15G/H5toA/etbYP0f5FiECYsSMsBkqzjcORrPP5a X-Developer-Key: i=pavee.zheng@gmail.com; a=ed25519; pk=tKWX/JHvHgKJscWsVefc3+t39eSysVDI8/ZkQl1Rlyo= X-Endpoint-Received: by B4 Relay for pavee.zheng@gmail.com/20261203 with auth_id=1729 List-Id: B4 Relay Submissions Commit 5e7c8942012b ("namespace: don't reveal overmounted dentries that lost their mounts") changed maybe_free_mountpoint() to skip clearing DCACHE_MOUNTED whenever cant_mount(dentry) is set, so that removed names continue to enter __traverse_mounts() and fail. However, DCACHE_CANT_MOUNT is also set on live dentries that are not unlinked, including ephemeral procfs files under /proc//fd, fdinfo, map_files, and net, /proc/self, /proc/thread-self, and HFS resource forks. Since commit aad0a8ec0312 ("namespace: allow bind mounts of ephemeral procfs files again") dropped the cant_mount() check from d_set_mounted(), attach_recursive_mnt() can pin such a dentry with get_mountpoint(). When unpin_mountpoint() calls maybe_free_mountpoint(), the mountpoint is unhashed and freed while DCACHE_MOUNTED remains set. A subsequent get_mountpoint() on the same still-linked dentry sees d_mountpoint(dentry) with !d_unlinked(dentry), finds no entry in lookup_mountpoint(), receives -EBUSY from d_set_mounted(), and loops indefinitely while holding namespace_sem for writing. This hangs tools/testing/selftests/filesystems/mount_cycle/procfs_source_test in no_tuck_beneath_fdinfo_copy and blocks unrelated readers of /proc/self/mounts on namespace_sem. Clear DCACHE_MOUNTED in maybe_free_mountpoint() whenever !cant_mount(dentry) || !d_unlinked(dentry), keeping the flag only for removed names that are both cant_mount() and d_unlinked(). Removed names are unhashed by __detach_mounts() before mounts are detached and are never root dentries, so they keep DCACHE_MOUNTED as intended. Checking d_unlinked() matches d_set_mounted() and get_mountpoint() (including for IS_ROOT() dentries), while keeping !cant_mount(dentry) ensures dentries dropped by d_invalidate() still clear DCACHE_MOUNTED so find_submount() terminates. Fixes: 5e7c8942012b ("namespace: don't reveal overmounted dentries that lost their mounts") Signed-off-by: Pavee Zheng --- Found and prepared with the assistance of an AI coding assistant. Based on vfs.git vfs.all (d8d9179592a5), which integrates both 5e7c8942012b (vfs-7.5.mount) and aad0a8ec0312 (vfs.fixes); also verified to apply cleanly to vfs-7.5.mount (63fab288c315). No Cc: stable tag is included because commit 5e7c8942012b is not yet in a released kernel. Verification: - Built out-of-tree for arm64 with gcc 12.2.0 (CONFIG_PROVE_LOCKING=y, CONFIG_DEBUG_ATOMIC_SLEEP=y, CONFIG_DETECT_HUNG_TASK=y, CONFIG_SOFTLOCKUP_DETECTOR=y, CONFIG_FUSE_FS=y): 0 warnings on normal build and make W=1 fs/namespace.o. - Booted in QEMU (qemu-system-aarch64 -M virt -smp 4, Linux 7.4.0-rc4+ aarch64) and ran: - tools/testing/selftests/filesystems/mount_cycle/procfs_source_test: 10/10 passed (previously livelocked in no_tuck_beneath_fdinfo_copy holding namespace_sem). - tools/testing/selftests/filesystems/mount_cycle/detach_mounts_test: 11/11 passed. - tools/testing/selftests/filesystems/fuse/unlink_reval_test: 4/4 passed. - Remaining mount_cycle tests: mount_cover_test (11/11), unheld_umount_test (5/5), unmounted_tree_test (5/5), overmount_reparent_test (1/1), overmount_ns_file_test (1/1), nsfs_rbind_loop_test (1/1), locked_handle_test (3/3), and loop_cycle_test (5 passed, 6 skipped due to optional holder/fs configs not enabled in the minimal VM config). - 0 warnings, lockdep splats, hung tasks, or softlockups in dmesg. Scope limitations: - Built and runtime-tested on arm64 QEMU only (not x86_64 or other architectures); CONFIG_KASAN was not enabled; 6 optional-config subtests in loop_cycle_test were skipped. --- fs/namespace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index 1b163c7f5189..e9282af4db96 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -976,14 +976,15 @@ static int get_mountpoint(struct dentry *dentry, struct pinned_mountpoint *m) * * A removed name keeps DCACHE_MOUNTED so that a walk which found the * name earlier continues walking mounts and fails. The bit dies with the - * dentry or in d_delete(). + * dentry or in d_delete(). Live dentries that also carry DCACHE_CANT_MOUNT + * (such as ephemeral procfs files) are not unlinked and must clear it. */ static void maybe_free_mountpoint(struct mountpoint *mp, struct list_head *list) { if (hlist_empty(&mp->m_list) && hlist_empty(&mp->m_covers)) { struct dentry *dentry = mp->m_dentry; spin_lock(&dentry->d_lock); - if (!cant_mount(dentry)) + if (!cant_mount(dentry) || !d_unlinked(dentry)) dentry->d_flags &= ~DCACHE_MOUNTED; spin_unlock(&dentry->d_lock); dput_to_list(dentry, list); --- base-commit: d8d9179592a52044a52591b31b914cfc0edbf36d change-id: 20261205-patch-vfs-maybe-free-mountpoint-210f367af6d5 Best regards, -- Pavee Zheng