Skip to content

Commit 48ba083

Browse files
wlukowiczaxboe
authored andcommitted
io_uring: fix size calculation when registering buf ring
Using struct_size() to calculate the size of io_uring_buf_ring will sum the size of the struct and of the bufs array. However, the struct's fields are overlaid with the array making the calculated size larger than it should be. When registering a ring with N * PAGE_SIZE / sizeof(struct io_uring_buf) entries, i.e. with fully filled pages, the calculated size will span one more page than it should and io_uring will try to pin the following page. Depending on how the application allocated the ring, it might succeed using an unrelated page or fail returning EFAULT. The size of the ring should be the product of ring_entries and the size of io_uring_buf, i.e. the size of the bufs array only. Fixes: c7fb194 ("io_uring: add support for ring mapped supplied buffers") Signed-off-by: Wojciech Lukowicz <[email protected]> Reviewed-by: Gabriel Krisman Bertazi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 6bf65a1 commit 48ba083

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

io_uring/kbuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
505505
}
506506

507507
pages = io_pin_pages(reg.ring_addr,
508-
struct_size(br, bufs, reg.ring_entries),
508+
flex_array_size(br, bufs, reg.ring_entries),
509509
&nr_pages);
510510
if (IS_ERR(pages)) {
511511
kfree(free_bl);

0 commit comments

Comments
 (0)