Skip to content

Commit 03b0d3a

Browse files
braunermehmetb0
authored andcommitted
epoll: annotate racy check
BugLink: https://bugs.launchpad.net/bugs/2095283 [ Upstream commit 6474353 ] Epoll relies on a racy fastpath check during __fput() in eventpoll_release() to avoid the hit of pointlessly acquiring a semaphore. Annotate that race by using WRITE_ONCE() and READ_ONCE(). Link: https://lore.kernel.org/r/66edfb3c.050a0220.3195df.001a.GAE@google.com Link: https://lore.kernel.org/r/20240925-fungieren-anbauen-79b334b00542@brauner Reviewed-by: Jan Kara <jack@suse.cz> Reported-by: syzbot+3b6b32dc50537a49bb4a@syzkaller.appspotmail.com Signed-off-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
1 parent d9b3ce9 commit 03b0d3a

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

fs/eventpoll.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,8 @@ static int ep_remove(struct eventpoll *ep, struct epitem *epi)
696696
to_free = NULL;
697697
head = file->f_ep;
698698
if (head->first == &epi->fllink && !epi->fllink.next) {
699-
file->f_ep = NULL;
699+
/* See eventpoll_release() for details. */
700+
WRITE_ONCE(file->f_ep, NULL);
700701
if (!is_file_epoll(file)) {
701702
struct epitems_head *v;
702703
v = container_of(head, struct epitems_head, epitems);
@@ -1460,7 +1461,8 @@ static int attach_epitem(struct file *file, struct epitem *epi)
14601461
spin_unlock(&file->f_lock);
14611462
goto allocate;
14621463
}
1463-
file->f_ep = head;
1464+
/* See eventpoll_release() for details. */
1465+
WRITE_ONCE(file->f_ep, head);
14641466
to_free = NULL;
14651467
}
14661468
hlist_add_head_rcu(&epi->fllink, file->f_ep);

include/linux/eventpoll.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static inline void eventpoll_release(struct file *file)
4242
* because the file in on the way to be removed and nobody ( but
4343
* eventpoll ) has still a reference to this file.
4444
*/
45-
if (likely(!file->f_ep))
45+
if (likely(!READ_ONCE(file->f_ep)))
4646
return;
4747

4848
/*

0 commit comments

Comments
 (0)