Skip to content

Commit 7996883

Browse files
committed
io_uring/rw: add defensive hardening for negative kbuf lengths
No real bug here, just being a bit defensive in ensuring that whatever gets passed into io_put_kbuf() is always >= 0 and not some random error value. Reviewed-by: Gabriel Krisman Bertazi <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 02b8d41 commit 7996883

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

io_uring/rw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ void io_req_rw_complete(struct io_tw_req tw_req, io_tw_token_t tw)
580580
io_req_io_end(req);
581581

582582
if (req->flags & (REQ_F_BUFFER_SELECTED|REQ_F_BUFFER_RING))
583-
req->cqe.flags |= io_put_kbuf(req, req->cqe.res, NULL);
583+
req->cqe.flags |= io_put_kbuf(req, max(req->cqe.res, 0), NULL);
584584

585585
io_req_rw_cleanup(req, 0);
586586
io_req_task_complete(tw_req, tw);
@@ -1379,7 +1379,7 @@ int io_do_iopoll(struct io_ring_ctx *ctx, bool force_nonspin)
13791379
list_del(&req->iopoll_node);
13801380
wq_list_add_tail(&req->comp_list, &ctx->submit_state.compl_reqs);
13811381
nr_events++;
1382-
req->cqe.flags = io_put_kbuf(req, req->cqe.res, NULL);
1382+
req->cqe.flags = io_put_kbuf(req, max(req->cqe.res, 0), NULL);
13831383
if (!io_is_uring_cmd(req))
13841384
io_req_rw_cleanup(req, 0);
13851385
}

0 commit comments

Comments
 (0)