Skip to content

Commit 8efff2a

Browse files
axboegregkh
authored andcommitted
io_uring/eventfd: ensure io_eventfd_signal() defers another RCU period
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>
1 parent 03753bf commit 8efff2a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

io_uring/io_uring.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,13 @@ static __cold void io_queue_deferred(struct io_ring_ctx *ctx)
537537
}
538538
}
539539

540+
static void io_eventfd_free(struct rcu_head *rcu)
541+
{
542+
struct io_ev_fd *ev_fd = container_of(rcu, struct io_ev_fd, rcu);
543+
544+
eventfd_ctx_put(ev_fd->cq_ev_fd);
545+
kfree(ev_fd);
546+
}
540547

541548
static void io_eventfd_ops(struct rcu_head *rcu)
542549
{
@@ -550,10 +557,8 @@ static void io_eventfd_ops(struct rcu_head *rcu)
550557
* ordering in a race but if references are 0 we know we have to free
551558
* it regardless.
552559
*/
553-
if (atomic_dec_and_test(&ev_fd->refs)) {
554-
eventfd_ctx_put(ev_fd->cq_ev_fd);
555-
kfree(ev_fd);
556-
}
560+
if (atomic_dec_and_test(&ev_fd->refs))
561+
call_rcu(&ev_fd->rcu, io_eventfd_free);
557562
}
558563

559564
static void io_eventfd_signal(struct io_ring_ctx *ctx)

0 commit comments

Comments
 (0)