Modifying the loop variable with array_index_nospec() can skip indices and cause an infinite loop when end > IO_RINGFD_REG_MAX and all slots are occupied. Use a separate 'idx' variable instead. Signed-off-by: Yang Xiuwei diff --git a/io_uring/tctx.c b/io_uring/tctx.c index 6d6f44215ec8..fcf79df923a0 100644 --- a/io_uring/tctx.c +++ b/io_uring/tctx.c @@ -221,14 +221,15 @@ void io_uring_unreg_ringfd(void) int io_ring_add_registered_file(struct io_uring_task *tctx, struct file *file, int start, int end) { - int offset; + int offset, idx; + for (offset = start; offset < end; offset++) { - offset = array_index_nospec(offset, IO_RINGFD_REG_MAX); - if (tctx->registered_rings[offset]) + idx = array_index_nospec(offset, IO_RINGFD_REG_MAX); + if (tctx->registered_rings[idx]) continue; - tctx->registered_rings[offset] = file; - return offset; + tctx->registered_rings[idx] = file; + return idx; } return -EBUSY; } -- 2.25.1