io_uring: don't attempt to mmap larger than what the user asks for
authorJens Axboe <axboe@kernel.dk>
Wed, 29 May 2024 15:38:38 +0000 (09:38 -0600)
committerJens Axboe <axboe@kernel.dk>
Wed, 29 May 2024 15:53:14 +0000 (09:53 -0600)
commit06fe9b1df1086b42718d632aa57e8f7cd1a66a21
tree2b76323364eae2e8177d8418ad204e114e7c2e3a
parent1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0
io_uring: don't attempt to mmap larger than what the user asks for

If IORING_FEAT_SINGLE_MMAP is ignored, as can happen if an application
uses an ancient liburing or does setup manually, then 3 mmap's are
required to map the ring into userspace. The kernel will still have
collapsed the mappings, however userspace may ask for mapping them
individually. If so, then we should not use the full number of ring
pages, as it may exceed the partial mapping. Doing so will yield an
-EFAULT from vm_insert_pages(), as we pass in more pages than what the
application asked for.

Cap the number of pages to match what the application asked for, for
the particular mapping operation.

Reported-by: Lucas Mülling <lmulling@proton.me>
Link: https://github.com/axboe/liburing/issues/1157
Fixes: 3ab1db3c6039 ("io_uring: get rid of remap_pfn_range() for mapping rings/sqes")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/memmap.c