linux-yocto/fs/proc
Al Viro 3baad7b930 fix proc_sys_compare() handling of in-lookup dentries
[ Upstream commit b969f96148 ]

There's one case where ->d_compare() can be called for an in-lookup
dentry; usually that's nothing special from ->d_compare() point of
view, but... proc_sys_compare() is weird.

The thing is, /proc/sys subdirectories can look differently for
different processes.  Up to and including having the same name
resolve to different dentries - all of them hashed.

The way it's done is ->d_compare() refusing to admit a match unless
this dentry is supposed to be visible to this caller.  The information
needed to discriminate between them is stored in inode; it is set
during proc_sys_lookup() and until it's done d_splice_alias() we really
can't tell who should that dentry be visible for.

Normally there's no negative dentries in /proc/sys; we can run into
a dying dentry in RCU dcache lookup, but those can be safely rejected.

However, ->d_compare() is also called for in-lookup dentries, before
they get positive - or hashed, for that matter.  In case of match
we will wait until dentry leaves in-lookup state and repeat ->d_compare()
afterwards.  In other words, the right behaviour is to treat the
name match as sufficient for in-lookup dentries; if dentry is not
for us, we'll see that when we recheck once proc_sys_lookup() is
done with it.

While we are at it, fix the misspelled READ_ONCE and WRITE_ONCE there.

Fixes: d9171b9345 ("parallel lookups machinery, part 4 (and last)")
Reported-by: NeilBrown <neilb@brown.name>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-07-17 18:32:05 +02:00
..
array.c fs/proc: do_task_stat: Fix ESP not readable during coredump 2025-02-21 13:49:39 +01:00
base.c fs/procfs: fix the comment above proc_pid_wchan() 2025-04-10 14:33:37 +02:00
bootconfig.c
cmdline.c
consoles.c
cpuinfo.c
devices.c
fd.c
fd.h
generic.c proc: fix UAF in proc_get_inode() 2025-03-28 21:59:01 +01:00
inode.c fix proc_sys_compare() handling of in-lookup dentries 2025-07-17 18:32:05 +02:00
internal.h proc: fix UAF in proc_get_inode() 2025-03-28 21:59:01 +01:00
interrupts.c
Kconfig
kcore.c fs/proc/kcore.c: Clear ret value in read_kcore_iter after successful iov_iter_zero 2024-12-14 19:54:15 +01:00
kmsg.c
loadavg.c
Makefile
meminfo.c
namespaces.c
nommu.c
page.c
proc_net.c
proc_sysctl.c fix proc_sys_compare() handling of in-lookup dentries 2025-07-17 18:32:05 +02:00
proc_tty.c
root.c
self.c
softirqs.c proc/softirqs: replace seq_printf with seq_put_decimal_ull_width 2024-12-14 19:53:10 +01:00
stat.c
task_mmu.c fs/proc/task_mmu: indicate PM_FILE for PMD-mapped file THP 2024-08-03 08:49:28 +02:00
task_nommu.c
thread_self.c
uptime.c
util.c
version.c
vmcore.c fs/proc: fix softlockup in __read_vmcore (part 2) 2025-01-23 17:17:14 +01:00