Skip to content

Commit cd053d7

Browse files
Naupjjinaxboe
authored andcommitted
io_uring: fix dangling iovec after provided-buffer bundle grow failure
When growing a provided-buffer bundle, the old cached iovec is freed before the new buffers have all been validated. If validation fails, the request still points at the freed iovec, which can be freed again during completion cleanup. Fix this by deferring the free of the old cached iovec until validation has succeeded. On failure, free the newly allocated iovec and leave the request pointing at the original one. Fixes: 4680058 ("io_uring/kbuf: validate ring provided buffer addresses with access_ok()") Signed-off-by: Hao-Yu Yang <naup96721@gmail.com> Link: https://patch.msgid.link/20260706183304.919275-1-naup96721@gmail.com Suggested-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 58481c7 commit cd053d7

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

io_uring/kbuf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,6 @@ static int io_ring_buffers_peek(struct io_kiocb *req, struct buf_sel_arg *arg,
287287
iov = kmalloc_objs(struct iovec, nr_avail);
288288
if (unlikely(!iov))
289289
return -ENOMEM;
290-
if (arg->mode & KBUF_MODE_FREE)
291-
kfree(arg->iovs);
292290
arg->iovs = iov;
293291
nr_iovs = nr_avail;
294292
} else if (nr_avail < nr_iovs) {
@@ -330,6 +328,9 @@ static int io_ring_buffers_peek(struct io_kiocb *req, struct buf_sel_arg *arg,
330328
buf = io_ring_head_to_buf(br, ++head, bl->mask);
331329
} while (--nr_iovs);
332330

331+
if (arg->mode & KBUF_MODE_FREE)
332+
kfree(arg->iovs);
333+
333334
if (head == tail)
334335
req->flags |= REQ_F_BL_EMPTY;
335336

0 commit comments

Comments
 (0)