Skip to content

Commit 929a3af

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix use-after-free by io_cleanup_req()
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 <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 297a31e commit 929a3af

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
@@ -1260,6 +1260,9 @@ static void __io_req_aux_free(struct io_kiocb *req)
12601260
{
12611261
struct io_ring_ctx *ctx = req->ctx;
12621262

1263+
if (req->flags & REQ_F_NEED_CLEANUP)
1264+
io_cleanup_req(req);
1265+
12631266
kfree(req->io);
12641267
if (req->file) {
12651268
if (req->flags & REQ_F_FIXED_FILE)
@@ -1275,9 +1278,6 @@ static void __io_free_req(struct io_kiocb *req)
12751278
{
12761279
__io_req_aux_free(req);
12771280

1278-
if (req->flags & REQ_F_NEED_CLEANUP)
1279-
io_cleanup_req(req);
1280-
12811281
if (req->flags & REQ_F_INFLIGHT) {
12821282
struct io_ring_ctx *ctx = req->ctx;
12831283
unsigned long flags;

0 commit comments

Comments
 (0)