Skip to content

Commit a523599

Browse files
committed
Merge tag 'io_uring-5.19-2022-07-21' of git://git.kernel.dk/linux-block
Pull io_uring fixes from Jens Axboe: "Fix for a bad kfree() introduced in this cycle, and a quick fix for disabling buffer recycling for IORING_OP_READV. The latter will get reworked for 5.20, but it gets the job done for 5.19" * tag 'io_uring-5.19-2022-07-21' of git://git.kernel.dk/linux-block: io_uring: do not recycle buffer in READV io_uring: fix free of unallocated buffer list
2 parents d945404 + 934447a commit a523599

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

fs/io_uring.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,14 @@ static void io_kbuf_recycle(struct io_kiocb *req, unsigned issue_flags)
17371737
(req->flags & REQ_F_PARTIAL_IO))
17381738
return;
17391739

1740+
/*
1741+
* READV uses fields in `struct io_rw` (len/addr) to stash the selected
1742+
* buffer data. However if that buffer is recycled the original request
1743+
* data stored in addr is lost. Therefore forbid recycling for now.
1744+
*/
1745+
if (req->opcode == IORING_OP_READV)
1746+
return;
1747+
17401748
/*
17411749
* We don't need to recycle for REQ_F_BUFFER_RING, we can just clear
17421750
* the flag and hence ensure that bl->head doesn't get incremented.
@@ -12931,7 +12939,7 @@ static int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
1293112939
{
1293212940
struct io_uring_buf_ring *br;
1293312941
struct io_uring_buf_reg reg;
12934-
struct io_buffer_list *bl;
12942+
struct io_buffer_list *bl, *free_bl = NULL;
1293512943
struct page **pages;
1293612944
int nr_pages;
1293712945

@@ -12963,7 +12971,7 @@ static int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
1296312971
if (bl->buf_nr_pages || !list_empty(&bl->buf_list))
1296412972
return -EEXIST;
1296512973
} else {
12966-
bl = kzalloc(sizeof(*bl), GFP_KERNEL);
12974+
free_bl = bl = kzalloc(sizeof(*bl), GFP_KERNEL);
1296712975
if (!bl)
1296812976
return -ENOMEM;
1296912977
}
@@ -12972,7 +12980,7 @@ static int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
1297212980
struct_size(br, bufs, reg.ring_entries),
1297312981
&nr_pages);
1297412982
if (IS_ERR(pages)) {
12975-
kfree(bl);
12983+
kfree(free_bl);
1297612984
return PTR_ERR(pages);
1297712985
}
1297812986

0 commit comments

Comments
 (0)