Skip to content

Commit 43eef70

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix corner case forgetting to vunmap
io_pages_unmap() is a bit tricky in trying to figure whether the pages were previously vmap'ed or not. In particular If there is juts one page it belives there is no need to vunmap. Paired io_pages_map(), however, could've failed io_mem_alloc_compound() and attempted to io_mem_alloc_single(), which does vmap, and that leads to unpaired vmap. The solution is to fail if io_mem_alloc_compound() can't allocate a single page. That's the easiest way to deal with it, and those two functions are getting removed soon, so no need to overcomplicate it. Cc: stable@vger.kernel.org Fixes: 3ab1db3 ("io_uring: get rid of remap_pfn_range() for mapping rings/sqes") Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/477e75a3907a2fe83249e49c0a92cd480b2c60e0.1732569842.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 49c5c63 commit 43eef70

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

io_uring/memmap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ void *io_pages_map(struct page ***out_pages, unsigned short *npages,
7373
ret = io_mem_alloc_compound(pages, nr_pages, size, gfp);
7474
if (!IS_ERR(ret))
7575
goto done;
76+
if (nr_pages == 1)
77+
goto fail;
7678

7779
ret = io_mem_alloc_single(pages, nr_pages, size, gfp);
7880
if (!IS_ERR(ret)) {
@@ -81,7 +83,7 @@ void *io_pages_map(struct page ***out_pages, unsigned short *npages,
8183
*npages = nr_pages;
8284
return ret;
8385
}
84-
86+
fail:
8587
kvfree(pages);
8688
*out_pages = NULL;
8789
*npages = 0;

0 commit comments

Comments
 (0)