Fwd: [PATCH 6/6] io_uring/epoll: disallow adding an epoll file to an epoll context

7 views
Skip to first unread message

Juan José

unread,
Jul 30, 2026, 5:08:10 PM (10 days ago) Jul 30
to li...@googlegroups.com
Hi,

Something is about to change regarding epoll. I was mentioned in this email, and I've forwarded it to anyone who's interested.
It looks like it won't break libuv, but it's worth keeping an eye on.

Regards,
        Juan


---------- Forwarded message ---------
From: Xi Ruoyao <xry...@xry111.site>
Date: Tue, Jul 28, 2026 at 8:29 PM
Subject: Re: [PATCH 6/6] io_uring/epoll: disallow adding an epoll file to an epoll context
To: Jens Axboe <ax...@kernel.dk>, <io-u...@vger.kernel.org>
Cc: <linux-...@vger.kernel.org>, <bra...@kernel.org>, Linus Torvalds <torv...@linux-foundation.org>, Juan José <soyjua...@gmail.com>


On Thu, 2026-05-14 at 08:07 -0600, Jens Axboe wrote:
> One of the nastier things about epoll is how it allows adding epoll
> files to epoll contexts. This leads to all sorts of loop detection
> code, and has been a source of issues in the past.
>
> Arguably adding IORING_EPOLL_CTL is a historical mistake on the
> io_uring side, but we're kind of stuck with it now as it does seem
> to be in use according to code searches. But we can at least minimize
> the damage a bit and just disallow this part of epoll, where nesting
> issues can arise.

libuv uses this ... thing and there's even a test case against
exercising the code path adding an epoll file:

- https://github.com/libuv/libuv/commit/3b6a1a14caee
- https://github.com/libuv/libuv/blob/09591002d38e/test/test-poll.c#L690

And the test triggers an abort on the EINVAL at
https://github.com/libuv/libuv/blob/09591002d38e/src/unix/linux.c#L1360

I'm unsure what to do here.

> Suggested-by: Linus Torvalds <torv...@linux-foundation.org>
> Signed-off-by: Jens Axboe <ax...@kernel.dk>
> ---
>  io_uring/epoll.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/io_uring/epoll.c b/io_uring/epoll.c
> index b9db8bde27ec..eecd748cad01 100644
> --- a/io_uring/epoll.c
> +++ b/io_uring/epoll.c
> @@ -62,6 +62,9 @@ int io_epoll_ctl(struct io_kiocb *req, unsigned int
> issue_flags)
>       CLASS(fd, tf)(ie->fd);
>       if (fd_empty(tf))
>               return -EBADF;
> +     /* disallow adding an epoll context to another epoll context
> */
> +     if (ie->op == EPOLL_CTL_ADD && is_file_epoll(fd_file(tf)))
> +             return -EINVAL;
>  
>       key.file = fd_file(tf);
>       key.fd = ie->fd;

--
Xi Ruoyao <xry...@xry111.site>
Reply all
Reply to author
Forward
0 new messages