]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
io_uring/kbuf: fix memory leak if io_buffer_add_list fails
authorJens Axboe <axboe@kernel.dk>
Thu, 5 Feb 2026 15:38:20 +0000 (08:38 -0700)
committerJens Axboe <axboe@kernel.dk>
Thu, 5 Feb 2026 18:13:16 +0000 (11:13 -0700)
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: c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/kbuf.c

index 796d131107ddb955b324d98d613d65e4e90f1840..67d4fe576473ab3df5c9233751d4f7d4804471b6 100644 (file)
@@ -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);