Skip to content

Commit ec8516f

Browse files
Dylan Yudakenaxboe
authored andcommitted
io_uring: fix free of unallocated buffer list
in the error path of io_register_pbuf_ring, only free bl if it was allocated. Reported-by: Dipanjan Das <mail.dipanjan.das@gmail.com> Fixes: c7fb194 ("io_uring: add support for ring mapped supplied buffers") Signed-off-by: Dylan Yudaken <dylany@fb.com> Reviewed-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/all/CANX2M5bXKw1NaHdHNVqssUUaBCs8aBpmzRNVEYEvV0n44P7ioA@mail.gmail.com/ Link: https://lore.kernel.org/all/CANX2M5YiZBXU3L6iwnaLs-HHJXRvrxM8mhPDiMDF9Y9sAvOHUA@mail.gmail.com/ Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent d785a77 commit ec8516f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/io_uring.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12931,7 +12931,7 @@ static int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
1293112931
{
1293212932
struct io_uring_buf_ring *br;
1293312933
struct io_uring_buf_reg reg;
12934-
struct io_buffer_list *bl;
12934+
struct io_buffer_list *bl, *free_bl = NULL;
1293512935
struct page **pages;
1293612936
int nr_pages;
1293712937

@@ -12963,7 +12963,7 @@ static int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
1296312963
if (bl->buf_nr_pages || !list_empty(&bl->buf_list))
1296412964
return -EEXIST;
1296512965
} else {
12966-
bl = kzalloc(sizeof(*bl), GFP_KERNEL);
12966+
free_bl = bl = kzalloc(sizeof(*bl), GFP_KERNEL);
1296712967
if (!bl)
1296812968
return -ENOMEM;
1296912969
}
@@ -12972,7 +12972,7 @@ static int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
1297212972
struct_size(br, bufs, reg.ring_entries),
1297312973
&nr_pages);
1297412974
if (IS_ERR(pages)) {
12975-
kfree(bl);
12975+
kfree(free_bl);
1297612976
return PTR_ERR(pages);
1297712977
}
1297812978

0 commit comments

Comments
 (0)