summaryrefslogtreecommitdiffstats
path: root/io_uring
diff options
context:
space:
mode:
authorWojciech Lukowicz <wlukowicz01@gmail.com>2023-02-18 18:41:41 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-03-11 13:55:30 +0100
commitb0498e95cae75615540d29682f830da1c190e0a9 (patch)
tree8a699a80ac84056ead8fca8042fd083044fcee66 /io_uring
parent1e276e8acb8e24bce493603d19a699f76a1583fa (diff)
downloadlinux-stable-b0498e95cae75615540d29682f830da1c190e0a9.tar.gz
linux-stable-b0498e95cae75615540d29682f830da1c190e0a9.tar.bz2
linux-stable-b0498e95cae75615540d29682f830da1c190e0a9.zip
io_uring: fix size calculation when registering buf ring
[ Upstream commit 48ba08374e779421ca34bd14b4834aae19fc3e6a ] 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: c7fb19428d67 ("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>
Diffstat (limited to 'io_uring')
-rw-r--r--io_uring/kbuf.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index e2c46889d5fa..746b137b96e9 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -509,7 +509,7 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
}
pages = io_pin_pages(reg.ring_addr,
- struct_size(br, bufs, reg.ring_entries),
+ flex_array_size(br, bufs, reg.ring_entries),
&nr_pages);
if (IS_ERR(pages)) {
kfree(free_bl);