Skip to content

Commit 8911798

Browse files
committed
io_uring/register: use stable SQ/CQ ring data during resize
Normally the kernel would not expect an application to modify any of the data shared with the kernel during a resize operation, but of course the kernel cannot always assume good intent on behalf of the application. As part of resizing the rings, existing SQEs and CQEs are copied over to the new storage. Resizing uses the masks in the newly allocated shared storage to index the arrays, however it's possible that malicious userspace could modify these after they have been sanity checked. Use the validated and locally stored CQ and SQ ring sizing for masking to ensure the values are both stable and valid. Fixes: 79cfe9e ("io_uring/register: add IORING_REGISTER_RESIZE_RINGS") Reported-by: Jann Horn <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent c1c03ee commit 8911798

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

io_uring/register.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
514514
goto overflow;
515515
for (i = o.rings->sq.head; i < tail; i++) {
516516
unsigned src_head = i & (ctx->sq_entries - 1);
517-
unsigned dst_head = i & n.rings->sq_ring_mask;
517+
unsigned dst_head = i & (p.sq_entries - 1);
518518

519519
n.sq_sqes[dst_head] = o.sq_sqes[src_head];
520520
}
@@ -533,7 +533,7 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
533533
}
534534
for (i = o.rings->cq.head; i < tail; i++) {
535535
unsigned src_head = i & (ctx->cq_entries - 1);
536-
unsigned dst_head = i & n.rings->cq_ring_mask;
536+
unsigned dst_head = i & (p.cq_entries - 1);
537537

538538
n.rings->cqes[dst_head] = o.rings->cqes[src_head];
539539
}

0 commit comments

Comments
 (0)