mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] proc: fix data-race in proc_invalidate_siblings_dcache()
@ 2026-12-01 10:46 Christian Brauner
  0 siblings, 0 replies; only message in thread
From: Christian Brauner @ 2026-12-01 10:46 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Alexander Viro, Jan Kara, linux-kernel,
	syzbot+c477bc599c896b5de237, Christian Brauner (Amutable)

proc_invalidate_siblings_dcache() reads the head of the sibling inode
list without holding the list's lock while an inode on that list can be
evicted and removed from it at the same time:

  BUG: KCSAN: data-race in proc_invalidate_siblings_dcache / proc_pid_evict_inode

  write (marked) to 0xffff8881048a01d0 of 8 bytes by task 6951 on cpu 0:
   __hlist_del include/linux/list.h:1045 [inline]
   hlist_del_init_rcu include/linux/rculist.h:238 [inline]
   proc_pid_evict_inode+0x7c/0xd0 fs/proc/base.c:1918
   proc_evict_inode+0x45/0xa0 fs/proc/inode.c:41
   evict+0x301/0x570 fs/inode.c:829
   iput_final fs/inode.c:2036 [inline]
   iput+0x44f/0x5d0 fs/inode.c:2085
   dentry_unlink_inode+0x29a/0x2b0 fs/dcache.c:510
   dentry_kill+0x135/0x4f0 fs/dcache.c:857
   finish_dput+0x9f/0x1d0 fs/dcache.c:1032
   dput+0x43/0x50 fs/dcache.c:1073
   proc_invalidate_siblings_dcache+0x1e6/0x2c0 fs/proc/inode.c:143
   proc_flush_pid+0x1d/0x30 fs/proc/base.c:3457
   release_task+0xa0c/0xba0 kernel/exit.c:292
   exit_notify kernel/exit.c:781 [inline]
   do_exit+0xd64/0x1530 kernel/exit.c:992

  read to 0xffff8881048a01d0 of 8 bytes by task 5112 on cpu 1:
   proc_invalidate_siblings_dcache+0x2a/0x2c0 fs/proc/inode.c:114
   proc_flush_pid+0x1d/0x30 fs/proc/base.c:3457
   release_task+0xa0c/0xba0 kernel/exit.c:292
   wait_task_zombie kernel/exit.c:1285 [inline]
   wait_consider_task+0x1131/0x1630 kernel/exit.c:1512

  value changed: 0xffff8881071611b0 -> 0xffff88810718e530

That's benign. Proc inodes are freed after an RCU grace period, the
list entry is removed under the lock so a second hlist_del_init_rcu()
is a nop, and igrab() fails for an inode that is being evicted. But the
head is an RCU protected pointer that we read under rcu_read_lock(). So
read it with rcu_dereference() like hlist_for_each_entry_rcu() does.
That also gets rid of the sparse warning about assigning an __rcu
pointer to a plain one.

Reported-by: syzbot+c477bc599c896b5de237@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c477bc599c896b5de237
Fixes: 26dbc60f385f ("proc: Generalize proc_sys_prune_dcache into proc_prune_siblings_dcache")
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 fs/proc/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 02aa3e5f8c930..7c402acad6692 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -115,7 +115,7 @@ void proc_invalidate_siblings_dcache(struct hlist_head *inodes, spinlock_t *lock
 	struct super_block *old_sb = NULL;
 
 	rcu_read_lock();
-	while ((node = hlist_first_rcu(inodes))) {
+	while ((node = rcu_dereference(hlist_first_rcu(inodes)))) {
 		struct proc_inode *ei = hlist_entry(node, struct proc_inode, sibling_inodes);
 		struct super_block *sb;
 		struct inode *inode;

---
base-commit: 9cf8c00eb41ff7cbedf3a3ee9ba77fd49d7dfb06
change-id: 20261201-work-procfs-kcsan_siblings-b9dddc86fcac


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-01 10:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 10:46 [PATCH] proc: fix data-race in proc_invalidate_siblings_dcache() Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®