Skip to content

Commit

Permalink
io_uring: fix use-after-free by io_cleanup_req()
Browse files Browse the repository at this point in the history
io_cleanup_req() should be called before req->io is freed, and so
shouldn't be after __io_free_req() -> __io_req_aux_free(). Also,
it will be ignored for in io_free_req_many(), which use
__io_req_aux_free().

Place cleanup_req() into __io_req_aux_free().

Fixes: 99bc4c3 ("io_uring: fix iovec leaks")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Pavel Begunkov authored and Jens Axboe committed Feb 19, 2020
1 parent 297a31e commit 929a3af
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,9 @@ static void __io_req_aux_free(struct io_kiocb *req)
{
struct io_ring_ctx *ctx = req->ctx;

if (req->flags & REQ_F_NEED_CLEANUP)
io_cleanup_req(req);

kfree(req->io);
if (req->file) {
if (req->flags & REQ_F_FIXED_FILE)
Expand All @@ -1275,9 +1278,6 @@ static void __io_free_req(struct io_kiocb *req)
{
__io_req_aux_free(req);

if (req->flags & REQ_F_NEED_CLEANUP)
io_cleanup_req(req);

if (req->flags & REQ_F_INFLIGHT) {
struct io_ring_ctx *ctx = req->ctx;
unsigned long flags;
Expand Down

0 comments on commit 929a3af

Please sign in to comment.