]> git.baikalelectronics.ru Git - kernel.git/commit
io_uring: fix size calculation when registering buf ring
authorWojciech Lukowicz <wlukowicz01@gmail.com>
Sat, 18 Feb 2023 18:41:41 +0000 (18:41 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 11 Mar 2023 12:55:30 +0000 (13:55 +0100)
commit07f813fdd83ee30d6cce83c8d512ec95fdb13e90
tree8a699a80ac84056ead8fca8042fd083044fcee66
parent6ff2f5db6fb1e1e3449888780fa5eace1984ff20
io_uring: fix size calculation when registering buf ring

[ Upstream commit eb33537bce72f6f9788cbed264bebef479636f33 ]

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: e790404d1245 ("io_uring: add support for ring mapped supplied buffers")
Signed-off-by: Wojciech Lukowicz <wlukowicz01@gmail.com>
Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>
Link: https://lore.kernel.org/r/20230218184141.70891-1-wlukowicz01@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
io_uring/kbuf.c