Skip to content

Commit 4b97480

Browse files
committed
io_uring/rw: free potentially allocated iovec on cache put failure
If a read/write request goes through io_req_rw_cleanup() and has an allocated iovec attached and fails to put to the rw_cache, then it may end up with an unaccounted iovec pointer. Have io_rw_recycle() return whether it recycled the request or not, and use that to gauge whether to free a potential iovec or not. Reviewed-by: Nitesh Shetty <nj.shetty@samsung.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent da579f0 commit 4b97480

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

io_uring/rw.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,22 @@ static inline int io_import_rw_buffer(int rw, struct io_kiocb *req,
144144
return 0;
145145
}
146146

147-
static void io_rw_recycle(struct io_kiocb *req, unsigned int issue_flags)
147+
static bool io_rw_recycle(struct io_kiocb *req, unsigned int issue_flags)
148148
{
149149
struct io_async_rw *rw = req->async_data;
150150

151151
if (unlikely(issue_flags & IO_URING_F_UNLOCKED))
152-
return;
152+
return false;
153153

154154
io_alloc_cache_vec_kasan(&rw->vec);
155155
if (rw->vec.nr > IO_VEC_CACHE_SOFT_CAP)
156156
io_vec_free(&rw->vec);
157157

158-
if (io_alloc_cache_put(&req->ctx->rw_cache, rw))
158+
if (io_alloc_cache_put(&req->ctx->rw_cache, rw)) {
159159
io_req_async_data_clear(req, 0);
160+
return true;
161+
}
162+
return false;
160163
}
161164

162165
static void io_req_rw_cleanup(struct io_kiocb *req, unsigned int issue_flags)
@@ -190,7 +193,11 @@ static void io_req_rw_cleanup(struct io_kiocb *req, unsigned int issue_flags)
190193
*/
191194
if (!(req->flags & (REQ_F_REISSUE | REQ_F_REFCOUNT))) {
192195
req->flags &= ~REQ_F_NEED_CLEANUP;
193-
io_rw_recycle(req, issue_flags);
196+
if (!io_rw_recycle(req, issue_flags)) {
197+
struct io_async_rw *rw = req->async_data;
198+
199+
io_vec_free(&rw->vec);
200+
}
194201
}
195202
}
196203

0 commit comments

Comments
 (0)