* [PATCH] io_uring/kbuf: fix memory leak if io_buffer_add_list fails
@ 2026-02-05 15:43 Jens Axboe
2026-02-05 18:11 ` Pavel Begunkov
0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2026-02-05 15:43 UTC (permalink / raw)
To: io-uring; +Cc: Pavel Begunkov
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: ef62de3c4ad5 ("io_uring/kbuf: use region api for pbuf rings")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index 796d131107dd..67d4fe576473 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -669,8 +669,9 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
bl->buf_ring = br;
if (reg.flags & IOU_PBUF_RING_INC)
bl->flags |= IOBL_INC;
- io_buffer_add_list(ctx, bl, reg.bgid);
- return 0;
+ ret = io_buffer_add_list(ctx, bl, reg.bgid);
+ if (!ret)
+ return 0;
fail:
io_free_region(ctx->user, &bl->region);
kfree(bl);
--
Jens Axboe
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] io_uring/kbuf: fix memory leak if io_buffer_add_list fails
2026-02-05 15:43 [PATCH] io_uring/kbuf: fix memory leak if io_buffer_add_list fails Jens Axboe
@ 2026-02-05 18:11 ` Pavel Begunkov
2026-02-05 18:13 ` Jens Axboe
0 siblings, 1 reply; 3+ messages in thread
From: Pavel Begunkov @ 2026-02-05 18:11 UTC (permalink / raw)
To: Jens Axboe, io-uring
On 2/5/26 15:43, Jens Axboe wrote:
> 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: ef62de3c4ad5 ("io_uring/kbuf: use region api for pbuf rings")
Looks like that patch just moved the call, and the tag should be
more like:
c7fb19428d67d ("io_uring: add support for ring mapped supplied buffers")
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
>
> ---
>
> diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
> index 796d131107dd..67d4fe576473 100644
> --- a/io_uring/kbuf.c
> +++ b/io_uring/kbuf.c
> @@ -669,8 +669,9 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
> bl->buf_ring = br;
> if (reg.flags & IOU_PBUF_RING_INC)
> bl->flags |= IOBL_INC;
> - io_buffer_add_list(ctx, bl, reg.bgid);
> - return 0;
> + ret = io_buffer_add_list(ctx, bl, reg.bgid);
> + if (!ret)
> + return 0;
> fail:
> io_free_region(ctx->user, &bl->region);
> kfree(bl);
>
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] io_uring/kbuf: fix memory leak if io_buffer_add_list fails
2026-02-05 18:11 ` Pavel Begunkov
@ 2026-02-05 18:13 ` Jens Axboe
0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2026-02-05 18:13 UTC (permalink / raw)
To: Pavel Begunkov, io-uring
On 2/5/26 11:11 AM, Pavel Begunkov wrote:
> On 2/5/26 15:43, Jens Axboe wrote:
>> 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: ef62de3c4ad5 ("io_uring/kbuf: use region api for pbuf rings")
>
> Looks like that patch just moved the call, and the tag should be
> more like:
>
> c7fb19428d67d ("io_uring: add support for ring mapped supplied buffers")
Yep agree, I'll update the tag.
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-05 18:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-05 15:43 [PATCH] io_uring/kbuf: fix memory leak if io_buffer_add_list fails Jens Axboe
2026-02-05 18:11 ` Pavel Begunkov
2026-02-05 18:13 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox