Skip to content

Commit

Permalink
io_uring: fix multishot poll on overflow
Browse files Browse the repository at this point in the history
On overflow, multishot poll can still complete with the IORING_CQE_F_MORE
flag set.
If in the meantime the user clears a CQE and a the poll was cancelled then
the poll will post a CQE without the IORING_CQE_F_MORE (and likely result
-ECANCELED).

However when processing the application will encounter the non-overflow
CQE which indicates that there will be no more events posted. Typical
userspace applications would free memory associated with the poll in this
case.
It will then subsequently receive the earlier CQE which has overflowed,
which breaks the contract given by the IORING_CQE_F_MORE flag.

Signed-off-by: Dylan Yudaken <dylany@fb.com>
Link: https://lore.kernel.org/r/20220630091231.1456789-9-dylany@fb.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Dylan Yudaken authored and Jens Axboe committed Jul 25, 2022
1 parent 52120f0 commit a2da676
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions io_uring/poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,10 @@ static int io_poll_check_events(struct io_kiocb *req, bool *locked)
req->apoll_events);

if (!io_post_aux_cqe(ctx, req->cqe.user_data,
mask, IORING_CQE_F_MORE, true))
return -ECANCELED;
mask, IORING_CQE_F_MORE, false)) {
io_req_set_res(req, mask, 0);
return IOU_POLL_REMOVE_POLL_USE_RES;
}
} else {
ret = io_poll_issue(req, locked);
if (ret == IOU_STOP_MULTISHOT)
Expand Down

0 comments on commit a2da676

Please sign in to comment.