Skip to content

Commit 9a650c1

Browse files
axboemehmetb0
authored andcommitted
io_uring/eventfd: ensure io_eventfd_signal() defers another RCU period
BugLink: https://bugs.launchpad.net/bugs/2106770 Commit c9a4029 upstream. io_eventfd_do_signal() is invoked from an RCU callback, but when dropping the reference to the io_ev_fd, it calls io_eventfd_free() directly if the refcount drops to zero. This isn't correct, as any potential freeing of the io_ev_fd should be deferred another RCU grace period. Just call io_eventfd_put() rather than open-code the dec-and-test and free, which will correctly defer it another RCU grace period. Fixes: 21a091b ("io_uring: signal registered eventfd to process deferred task work") Reported-by: Jann Horn <jannh@google.com> Cc: stable@vger.kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CVE-2025-21655 Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Mehmet Basaran <mehmet.basaran@canonical.com>
1 parent 967b826 commit 9a650c1

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

io_uring/io_uring.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,14 @@ static __cold void io_queue_deferred(struct io_ring_ctx *ctx)
547547
}
548548
}
549549

550+
static void io_eventfd_free(struct rcu_head *rcu)
551+
{
552+
struct io_ev_fd *ev_fd = container_of(rcu, struct io_ev_fd, rcu);
553+
554+
eventfd_ctx_put(ev_fd->cq_ev_fd);
555+
kfree(ev_fd);
556+
}
557+
550558
void io_eventfd_ops(struct rcu_head *rcu)
551559
{
552560
struct io_ev_fd *ev_fd = container_of(rcu, struct io_ev_fd, rcu);
@@ -559,10 +567,8 @@ void io_eventfd_ops(struct rcu_head *rcu)
559567
* ordering in a race but if references are 0 we know we have to free
560568
* it regardless.
561569
*/
562-
if (atomic_dec_and_test(&ev_fd->refs)) {
563-
eventfd_ctx_put(ev_fd->cq_ev_fd);
564-
kfree(ev_fd);
565-
}
570+
if (atomic_dec_and_test(&ev_fd->refs))
571+
call_rcu(&ev_fd->rcu, io_eventfd_free);
566572
}
567573

568574
static void io_eventfd_signal(struct io_ring_ctx *ctx)

0 commit comments

Comments
 (0)