Linux driver-core infrastructure
 help / color / mirror / Atom feed
From: Sainath Manda <sainathmanda777@gmail.com>
To: gregkh@linuxfoundation.org, tj@kernel.org
Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org,
	Sainath Manda <sainathmanda777@gmail.com>,
	syzbot+f83fa2cf571bd7650422@syzkaller.appspotmail.com
Subject: [PATCH v2] kernfs: fix deadlock in epoll_ctl by waking pollfree
Date: Sun, 21 Jun 2026 16:13:10 +0530	[thread overview]
Message-ID: <20260621104310.18486-1-sainathmanda777@gmail.com> (raw)

Syzbot reported a task hung in do_epoll_ctl_file(). This is caused by an
AB-BA lock inversion between epoll's ep->mtx and kernfs node teardown.

Thread A (epoll_ctl) acquires ep->mtx, then attempts to acquire the
kernfs active reference during vfs_poll().
Thread B (kernfs_remove) deactivates the node and attempts to unhook
active epoll monitors, which requires ep->mtx.

This patch fixes the deadlock by utilizing the existing epoll POLLFREE
path. By calling wake_up_pollfree(&on->poll) before the waitqueue is
freed, epoll users are notified to detach their wait entries without
requiring kernfs teardown to acquire ep->mtx.

Reported-by: syzbot+f83fa2cf571bd7650422@syzkaller.appspotmail.com
Signed-off-by: Sainath Manda <sainathmanda777@gmail.com>
---
 fs/kernfs/file.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
index 1163aa769..db3fed4d7 100644
--- a/fs/kernfs/file.c
+++ b/fs/kernfs/file.c
@@ -600,6 +600,14 @@ static void kernfs_unlink_open_file(struct kernfs_node *kn,
 	}
 
 	if (list_empty(&on->files)) {
+		/*
+		 * @on->poll is embedded in @on and is about to be freed.  Tell
+		 * epoll users to detach their wait entries through the POLLFREE
+		 * callback path before the waitqueue disappears.  This path is
+		 * serialized by the waitqueue lock and doesn't require taking
+		 * eventpoll's ep->mtx from kernfs teardown.
+		 */
+		wake_up_pollfree(&on->poll);
 		rcu_assign_pointer(kn->attr.open, NULL);
 		kfree_rcu(on, rcu_head);
 	}
-- 
2.34.1


                 reply	other threads:[~2026-06-21 10:43 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=20260621104310.18486-1-sainathmanda777@gmail.com \
    --to=sainathmanda777@gmail.com \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+f83fa2cf571bd7650422@syzkaller.appspotmail.com \
    --cc=tj@kernel.org \
    /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