linux-stable/fs
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
..
9p
adfs
affs affs: don't write overlarge OFS data block size fields 2025-04-10 14:33:38 +02:00
afs
autofs
befs
bfs
btrfs btrfs: use btrfs_record_snapshot_destroy() during rmdir 2025-07-10 15:59:51 +02:00
cachefiles
ceph ceph: fix possible integer overflow in ceph_zero_objects() 2025-07-06 10:57:56 +02:00
coda
configfs configfs: Do not override creating attribute file failure in populate_attrs() 2025-06-27 11:07:25 +01:00
cramfs
crypto
debugfs
devpts
dlm dlm: make tcp still work in multi-link env 2025-06-04 14:40:05 +02:00
ecryptfs
efivarfs
efs
erofs
exfat exfat: fix the infinite loop in exfat_find_last_cluster() 2025-04-10 14:33:37 +02:00
exportfs
ext2
ext4 ext4: ensure i_size is smaller than maxbytes 2025-06-27 11:07:29 +01:00
f2fs f2fs: don't over-report free space or inodes in statvfs 2025-07-06 10:57:57 +02:00
fat
freevxfs
fscache
fuse fuse: Return EPERM rather than ENOSYS from link() 2025-06-04 14:40:02 +02:00
gfs2 gfs2: move msleep to sleepable context 2025-06-27 11:07:25 +01:00
hfs hfs/hfsplus: fix slab-out-of-bounds in hfs_bnode_read_key 2025-04-25 10:43:53 +02:00
hfsplus hfs/hfsplus: fix slab-out-of-bounds in hfs_bnode_read_key 2025-04-25 10:43:53 +02:00
hostfs
hpfs
hugetlbfs
iomap
isofs isofs: Prevent the use of too small fid 2025-04-25 10:43:53 +02:00
jbd2 jbd2: fix data-race and null-ptr-deref in jbd2_journal_dirty_metadata() 2025-06-27 11:07:26 +01:00
jffs2 jffs2: check jffs2_prealloc_raw_node_refs() result in few other places 2025-06-27 11:07:36 +01:00
jfs jfs: validate AG parameters in dbMount() to prevent crashes 2025-07-06 10:57:57 +02:00
kernfs kernfs: Relax constraint in draining guard 2025-06-27 11:07:11 +01:00
lockd
minix
netfs
nfs NFSv4/flexfiles: Fix handling of NFS level errors in I/O 2025-07-10 15:59:51 +02:00
nfs_common
nfsd nfsd: Initialize ssc before laundromat_work to prevent NULL dereference 2025-06-27 11:07:26 +01:00
nilfs2 nilfs2: do not propagate ENOENT error from nilfs_btree_propagate() 2025-06-27 11:07:13 +01:00
nls
notify
ntfs
ntfs3 fs/ntfs3: handle hdr_first_de() return value 2025-06-27 11:07:08 +01:00
ocfs2 ocfs2: fix possible memory leak in ocfs2_finish_quota_recovery 2025-06-27 11:07:13 +01:00
omfs fs: omfs: Use flexible-array member in struct omfs_extent 2025-07-06 10:58:03 +02:00
openpromfs
orangefs orangefs: Do not truncate file size 2025-06-04 14:40:08 +02:00
overlayfs ovl: Check for NULL d_inode() in ovl_dentry_upper() 2025-07-06 10:57:56 +02:00
proc fix proc_sys_compare() handling of in-lookup dentries 2025-07-17 18:32:05 +02:00
pstore
qnx4
qnx6
quota
ramfs
reiserfs
romfs
smb smb: client: fix race condition in negotiate timeout by using more precise timing 2025-07-10 15:59:49 +02:00
squashfs Squashfs: check return result of sb_min_blocksize 2025-06-27 11:07:13 +01:00
sysfs
sysv
tracefs
ubifs
udf
ufs
unicode
vboxsf
verity
xfs xfs: reset rootdir extent size hint after growfsrt 2025-06-27 11:07:20 +01:00
zonefs
aio.c
anon_inodes.c
attr.c
bad_inode.c
binfmt_elf_fdpic.c binfmt: Fix whitespace issues 2025-05-22 14:09:58 +02:00
binfmt_elf_test.c
binfmt_elf.c binfmt_elf: Move brk for static PIE even if ASLR disabled 2025-05-22 14:09:59 +02:00
binfmt_flat.c
binfmt_misc.c
binfmt_script.c
buffer.c
char_dev.c
compat_binfmt_elf.c
coredump.c coredump: hand a pidfd to the usermode coredump helper 2025-06-04 14:40:25 +02:00
d_path.c
dax.c
dcache.c
direct-io.c
drop_caches.c
eventfd.c
eventpoll.c
exec.c binfmt: Fix whitespace issues 2025-05-22 14:09:58 +02:00
fcntl.c
fhandle.c
file_table.c
file.c fs: consistently deref the files table with rcu_dereference_raw() 2025-04-25 10:43:27 +02:00
filesystems.c fs/filesystems: Fix potential unsigned integer underflow in fs_name() 2025-06-27 11:07:23 +01:00
fs_context.c
fs_parser.c
fs_pin.c
fs_struct.c
fs_types.c
fs-writeback.c
fsopen.c
init.c
inode.c
internal.h
ioctl.c
Kconfig nfs: add missing selections of CONFIG_CRC32 2025-04-25 10:43:52 +02:00
Kconfig.binfmt
kernel_read_file.c
libfs.c
locks.c
Makefile
mbcache.c
mount.h
mpage.c
namei.c
namespace.c attach_recursive_mnt(): do not lock the covering tree when sliding something under it 2025-07-06 10:58:00 +02:00
no-block.c
nsfs.c
open.c
pipe.c
pnode.c
pnode.h
posix_acl.c
proc_namespace.c
read_write.c
readdir.c
remap_range.c
select.c
seq_file.c
signalfd.c
splice.c
stack.c
stat.c
statfs.c
super.c
sync.c
sysctls.c
timerfd.c
userfaultfd.c mm/uffd: fix vma operation where start addr cuts part of vma 2025-06-27 11:07:04 +01:00
utimes.c
xattr.c