summaryrefslogtreecommitdiff
path: root/io_uring
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2025-01-08 11:16:13 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-01-17 13:34:47 +0100
commit6b63308c28987c6010b1180c72a6db4df6c68033 (patch)
treed077b4734bef7c35d81edfd1597a3c61ea7da02d /io_uring
parent3e871c1d51f9ffea70065c36a2d8615ffc3f05aa (diff)
downloadlinux-6b63308c28987c6010b1180c72a6db4df6c68033.tar.gz
linux-6b63308c28987c6010b1180c72a6db4df6c68033.tar.bz2
linux-6b63308c28987c6010b1180c72a6db4df6c68033.zip
io_uring/eventfd: ensure io_eventfd_signal() defers another RCU period
Commit c9a40292a44e78f71258b8522655bffaf5753bdb 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: 21a091b970cd ("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>
Diffstat (limited to 'io_uring')
-rw-r--r--io_uring/io_uring.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 9b58ba4616d4..480752fc3eb6 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -479,6 +479,13 @@ static __cold void io_queue_deferred(struct io_ring_ctx *ctx)
}
}
+static void io_eventfd_free(struct rcu_head *rcu)
+{
+ struct io_ev_fd *ev_fd = container_of(rcu, struct io_ev_fd, rcu);
+
+ eventfd_ctx_put(ev_fd->cq_ev_fd);
+ kfree(ev_fd);
+}
static void io_eventfd_ops(struct rcu_head *rcu)
{
@@ -492,10 +499,8 @@ static void io_eventfd_ops(struct rcu_head *rcu)
* ordering in a race but if references are 0 we know we have to free
* it regardless.
*/
- if (atomic_dec_and_test(&ev_fd->refs)) {
- eventfd_ctx_put(ev_fd->cq_ev_fd);
- kfree(ev_fd);
- }
+ if (atomic_dec_and_test(&ev_fd->refs))
+ call_rcu(&ev_fd->rcu, io_eventfd_free);
}
static void io_eventfd_signal(struct io_ring_ctx *ctx)