diff mbox series

[1/1] io_uring: annotate offset timeout races

Message ID 4de3685e185832a92a572df2be2c735d2e21a83d.1684506056.git.asml.silence@gmail.com (mailing list archive)
State New
Headers show
Series [1/1] io_uring: annotate offset timeout races | expand

Commit Message

Pavel Begunkov May 19, 2023, 2:21 p.m. UTC
It's racy to read ->cached_cq_tail without taking proper measures
(usually grabbing ->completion_lock) as timeout requests with CQE
offsets do, however they have never had a good semantics for from
when they start counting. Annotate racy reads with data_race().

Reported-by: syzbot+cb265db2f3f3468ef436@syzkaller.appspotmail.com
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/timeout.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jens Axboe May 20, 2023, 1:57 a.m. UTC | #1
On Fri, 19 May 2023 15:21:16 +0100, Pavel Begunkov wrote:
> It's racy to read ->cached_cq_tail without taking proper measures
> (usually grabbing ->completion_lock) as timeout requests with CQE
> offsets do, however they have never had a good semantics for from
> when they start counting. Annotate racy reads with data_race().
> 
> 

Applied, thanks!

[1/1] io_uring: annotate offset timeout races
      commit: 5498bf28d8f2bd63a46ad40f4427518615fb793f

Best regards,
diff mbox series

Patch

diff --git a/io_uring/timeout.c b/io_uring/timeout.c
index fc950177e2e1..350eb830b485 100644
--- a/io_uring/timeout.c
+++ b/io_uring/timeout.c
@@ -594,7 +594,7 @@  int io_timeout(struct io_kiocb *req, unsigned int issue_flags)
 		goto add;
 	}
 
-	tail = ctx->cached_cq_tail - atomic_read(&ctx->cq_timeouts);
+	tail = data_race(ctx->cached_cq_tail) - atomic_read(&ctx->cq_timeouts);
 	timeout->target_seq = tail + off;
 
 	/* Update the last seq here in case io_flush_timeouts() hasn't.