Skip to content

Commit d30deeb

Browse files
committed
eventpoll: move f_lock acquisition into ep_remove_file()
Let the helper own its critical section end-to-end: take &file->f_lock at the top, read file->f_ep inside the lock, release on exit. Callers (ep_remove() and eventpoll_release_file()) no longer need to wrap the call, and the function-comment lock-handoff contract is gone. Link: https://patch.msgid.link/20260423-work-epoll-uaf-v1-7-2470f9eec0f5@kernel.org Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
1 parent a6dc643 commit d30deeb

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

fs/eventpoll.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -855,18 +855,18 @@ static struct file *epi_fget(const struct epitem *epi)
855855
}
856856

857857
/*
858-
* Called with &file->f_lock held,
859-
* returns with it released
858+
* Takes &file->f_lock; returns with it released.
860859
*/
861860
static void ep_remove_file(struct eventpoll *ep, struct epitem *epi,
862861
struct file *file)
863862
{
864863
struct epitems_head *to_free = NULL;
865-
struct hlist_head *head = file->f_ep;
864+
struct hlist_head *head;
866865

867866
lockdep_assert_held(&ep->mtx);
868-
lockdep_assert_held(&file->f_lock);
869867

868+
spin_lock(&file->f_lock);
869+
head = file->f_ep;
870870
if (hlist_is_singular_node(&epi->fllink, head)) {
871871
/* See eventpoll_release() for details. */
872872
WRITE_ONCE(file->f_ep, NULL);
@@ -931,7 +931,6 @@ static void ep_remove(struct eventpoll *ep, struct epitem *epi)
931931
if (!file)
932932
return;
933933

934-
spin_lock(&file->f_lock);
935934
ep_remove_file(ep, epi, file);
936935

937936
if (ep_remove_epi(ep, epi))
@@ -1150,7 +1149,6 @@ void eventpoll_release_file(struct file *file)
11501149

11511150
ep_unregister_pollwait(ep, epi);
11521151

1153-
spin_lock(&file->f_lock);
11541152
ep_remove_file(ep, epi, file);
11551153
dispose = ep_remove_epi(ep, epi);
11561154

0 commit comments

Comments
 (0)