Skip to content

Commit

Permalink
io_uring: free iovec if file assignment fails
Browse files Browse the repository at this point in the history
[ Upstream commit 323b190 ]

We just return failure in this case, but we need to release the iovec
first. If we're doing IO with more than FAST_IOV segments, then the
iovec is allocated and must be freed.

Reported-by: syzbot+96b43810dfe9c3bb95ed@syzkaller.appspotmail.com
Fixes: 584b018 ("io_uring: move read/write file prep state into actual opcode handler")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
axboe authored and gregkh committed Apr 27, 2022
1 parent 71175f2 commit 74ffeba
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -3622,8 +3622,10 @@ static int io_read(struct io_kiocb *req, unsigned int issue_flags)
iovec = NULL;
}
ret = io_rw_init_file(req, FMODE_READ);
if (unlikely(ret))
if (unlikely(ret)) {
kfree(iovec);
return ret;
}
req->result = iov_iter_count(&s->iter);

if (force_nonblock) {
Expand Down Expand Up @@ -3742,8 +3744,10 @@ static int io_write(struct io_kiocb *req, unsigned int issue_flags)
iovec = NULL;
}
ret = io_rw_init_file(req, FMODE_WRITE);
if (unlikely(ret))
if (unlikely(ret)) {
kfree(iovec);
return ret;
}
req->result = iov_iter_count(&s->iter);

if (force_nonblock) {
Expand Down

0 comments on commit 74ffeba

Please sign in to comment.