Skip to content

Commit 442ae40

Browse files
committed
io_uring/kbuf: fix memory leak if io_buffer_add_list fails
io_register_pbuf_ring() ignores the return value of io_buffer_add_list(), which can fail if xa_store() returns an error (e.g., -ENOMEM). When this happens, the function returns 0 (success) to the caller, but the io_buffer_list structure is neither added to the xarray nor freed. In practice this requires failure injection to hit, hence not a real issue. But it should get fixed up none the less. Fixes: c7fb194 ("io_uring: add support for ring mapped supplied buffers") Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ccd18ce commit 442ae40

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

io_uring/kbuf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,9 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
669669
bl->buf_ring = br;
670670
if (reg.flags & IOU_PBUF_RING_INC)
671671
bl->flags |= IOBL_INC;
672-
io_buffer_add_list(ctx, bl, reg.bgid);
673-
return 0;
672+
ret = io_buffer_add_list(ctx, bl, reg.bgid);
673+
if (!ret)
674+
return 0;
674675
fail:
675676
io_free_region(ctx->user, &bl->region);
676677
kfree(bl);

0 commit comments

Comments
 (0)