Skip to content

Commit 44a9bd1

Browse files
committed
io_uring: fix failure to verify SQ_AFF cpu
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 <[email protected]>
1 parent e2033e3 commit 44a9bd1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/io_uring.c

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

24562456
if (p->flags & IORING_SETUP_SQ_AFF) {
2457-
int cpu = array_index_nospec(p->sq_thread_cpu,
2458-
nr_cpu_ids);
2457+
int cpu = p->sq_thread_cpu;
24592458

24602459
ret = -EINVAL;
2460+
if (cpu >= nr_cpu_ids)
2461+
goto err;
24612462
if (!cpu_online(cpu))
24622463
goto err;
24632464

0 commit comments

Comments
 (0)