Skip to content

Commit cf1fa8c

Browse files
axboegregkh
authored andcommitted
io_uring: fix failure to verify SQ_AFF cpu
commit 44a9bd1 upstream. The test case we have is rightfully failing with the current kernel: io_uring_setup(1, 0x7ffe2cafebe0), flags: IORING_SETUP_SQPOLL|IORING_SETUP_SQ_AFF, resv: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000, sq_thread_cpu: 4 expected -1, got 3 This is in a vm, and CPU3 is the last valid one, hence asking for 4 should fail the setup with -EINVAL, not succeed. The problem is that we're using array_index_nospec() with nr_cpu_ids as the index, hence we wrap and end up using CPU0 instead of CPU4. This makes the setup succeed where it should be failing. We don't need to use array_index_nospec() as we're not indexing any array with this. Instead just compare with nr_cpu_ids directly. This is fine as we're checking with cpu_online() afterwards. Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent bc9dcb2 commit cf1fa8c

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎fs/io_uring.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,10 +2330,11 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx,
23302330
ctx->sq_thread_idle = HZ;
23312331

23322332
if (p->flags & IORING_SETUP_SQ_AFF) {
2333-
int cpu = array_index_nospec(p->sq_thread_cpu,
2334-
nr_cpu_ids);
2333+
int cpu = p->sq_thread_cpu;
23352334

23362335
ret = -EINVAL;
2336+
if (cpu >= nr_cpu_ids)
2337+
goto err;
23372338
if (!cpu_online(cpu))
23382339
goto err;
23392340

0 commit comments

Comments
 (0)