linux/fs/proc
Krzysztof Wilczyński 16b02eb4b9
proc: only bump parent nlink when registering directories
proc_register() increments the parent directory's link count for every
entry it registers, while remove_proc_entry() and remove_proc_subtree()
decrement it only when the removed entry is a directory.  Regular files
thus inflate the parent's count while they exist, and leak one link
permanently on every create and remove cycle.

For example, /proc/bus/pci/00 with twenty-two device files and no
subdirectories reports nlink 24 instead of 2, and SR-IOV VF enable
and disable cycles, each creating and removing the VF config space
entries under /proc/bus/pci/<bus>, inflate the link count of that
directory without bound.

Before commit e06689bf57 ("proc: change ->nlink under
proc_subdir_lock"), the increment lived in proc_mkdir_data() and
proc_create_mount_point(), and was therefore applied only to
directories.  Moving it into proc_register() to bring it under
proc_subdir_lock dropped the S_ISDIR check.

Thus, move the nlink accounting into pde_subdir_insert() and
pde_erase(), only updating it for directories in both, so the link
count is always changed together with the directory entry itself.

Fixes: e06689bf57 ("proc: change ->nlink under proc_subdir_lock")
Cc: stable@vger.kernel.org # v5.5+
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Link: https://patch.msgid.link/20260613211005.921692-1-kwilczynski@kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-07-01 15:26:24 +02:00
..
array.c proc: protect ptrace_may_access() with exec_update_lock (part 1) 2026-06-05 10:00:55 +02:00
base.c mm.git review status for mm-hotfixes-stable..mm-nonmm-stable 2026-06-21 13:20:19 -07:00
bootconfig.c fs/proc: Skip bootloader comment if no embedded kernel parameters 2024-04-09 23:36:18 +09:00
cmdline.c
consoles.c proc: Add nbcon support for /proc/consoles 2024-09-04 15:56:33 +02:00
cpuinfo.c
devices.c
fd.c proc: protect ptrace_may_access() with exec_update_lock (FD links) 2026-06-05 10:00:55 +02:00
fd.h
generic.c proc: only bump parent nlink when registering directories 2026-07-01 15:26:24 +02:00
inode.c fs/proc: replace "__auto_type" with "const auto" 2025-12-08 15:32:15 -08:00
internal.h proc: protect ptrace_may_access() with exec_update_lock (FD links) 2026-06-05 10:00:55 +02:00
interrupts.c fs/procfs: Switch to irq_get_nr_irqs() 2024-10-16 21:56:59 +02:00
Kconfig virtio-mem: support CONFIG_PROC_VMCORE_DEVICE_RAM 2025-01-27 09:39:25 -05:00
kcore.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
kmsg.c
loadavg.c
Makefile genirq/proc: Speed up /proc/interrupts iteration 2026-05-26 16:21:15 +02:00
meminfo.c mm.git review status for linus..mm-stable 2026-04-15 12:59:16 -07:00
namespaces.c proc: protect ptrace_may_access() with exec_update_lock (part 1) 2026-06-05 10:00:55 +02:00
nommu.c fs: create helper file_user_path() for user displayed mapped file path 2023-10-19 11:03:15 +02:00
page.c fs/proc/page: remove unused KPMBITS 2025-11-20 14:03:42 -08:00
proc_net.c proc: subset=pid: Show /proc/self/net only for CAP_NET_ADMIN 2026-05-11 23:13:01 +02:00
proc_sysctl.c VFS: use wait_var_event for waiting in d_alloc_parallel() 2026-06-05 00:34:54 -04:00
proc_tty.c
root.c proc: handle subset=pid separately in userns visibility checks 2026-05-11 23:13:02 +02:00
self.c fs/proc: Don't lock root inode when creating "self" and "thread-self" 2026-03-06 10:24:11 +01:00
softirqs.c proc/softirqs: replace seq_printf with seq_put_decimal_ull_width 2024-11-07 07:40:14 -10:00
stat.c Updates for the NOHZ subsystem: 2026-06-15 13:48:52 +05:30
task_mmu.c fs/proc/task_mmu: do not warn on seeing non-migration pmd entry 2026-06-08 18:21:32 -07:00
task_nommu.c fs/proc/task_mmu: factor out proc_maps_private fields used by PROCMAP_QUERY 2025-09-13 16:54:48 -07:00
thread_self.c fs/proc: Don't lock root inode when creating "self" and "thread-self" 2026-03-06 10:24:11 +01:00
uptime.c tick/sched: Consolidate idle time fetching APIs 2026-06-02 21:27:26 +02:00
util.c
version.c
vmcore.c mm: rename my_zero_pfn() to zero_pfn() 2026-04-05 13:53:01 -07:00