Skip to content

Commit e1c7583

Browse files
superman-xptaxboe
authored andcommitted
io_uring: fix potential page leak in io_sqe_buffer_register()
If allocation of the 'imu' fails, then the existing pages aren't unpinned in the error path. This is mostly a theoretical issue, requiring fault injection to hit. Move unpin_user_pages() to unified error handling to fix the page leak issue. Fixes: d8c2237 ("io_uring: add io_pin_pages() helper") Signed-off-by: Penglei Jiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent f2320f1 commit e1c7583

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

io_uring/rsrc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,10 +809,8 @@ static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx,
809809

810810
imu->nr_bvecs = nr_pages;
811811
ret = io_buffer_account_pin(ctx, pages, nr_pages, imu, last_hpage);
812-
if (ret) {
813-
unpin_user_pages(pages, nr_pages);
812+
if (ret)
814813
goto done;
815-
}
816814

817815
size = iov->iov_len;
818816
/* store original address for later verification */
@@ -842,6 +840,8 @@ static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx,
842840
if (ret) {
843841
if (imu)
844842
io_free_imu(ctx, imu);
843+
if (pages)
844+
unpin_user_pages(pages, nr_pages);
845845
io_cache_free(&ctx->node_cache, node);
846846
node = ERR_PTR(ret);
847847
}

0 commit comments

Comments
 (0)