mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
	 linux-kernel@vger.kernel.org,
	 syzbot+c477bc599c896b5de237@syzkaller.appspotmail.com,
	 "Christian Brauner (Amutable)" <brauner@kernel.org>
Subject: [PATCH] proc: fix data-race in proc_invalidate_siblings_dcache()
Date: Tue, 01 Dec 2026 11:46:07 +0100	[thread overview]
Message-ID: <20261201-work-procfs-kcsan_siblings-v1-1-5b6de990d05d@kernel.org> (raw)

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


                 reply	other threads:[~2026-12-01 10:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201-work-procfs-kcsan_siblings-v1-1-5b6de990d05d@kernel.org \
    --to=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+c477bc599c896b5de237@syzkaller.appspotmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®