Skip to content

Commit 13a8f7b

Browse files
axboegregkh
authored andcommitted
io_uring/poll: correctly handle io_poll_add() return value on update
commit 84230ad upstream. When the core of io_uring was updated to handle completions consistently and with fixed return codes, the POLL_REMOVE opcode with updates got slightly broken. If a POLL_ADD is pending and then POLL_REMOVE is used to update the events of that request, if that update causes the POLL_ADD to now trigger, then that completion is lost and a CQE is never posted. Additionally, ensure that if an update does cause an existing POLL_ADD to complete, that the completion value isn't always overwritten with -ECANCELED. For that case, whatever io_poll_add() set the value to should just be retained. Cc: stable@vger.kernel.org Fixes: 97b388d ("io_uring: handle completions in the core") Reported-by: syzbot+641eec6b7af1f62f2b99@syzkaller.appspotmail.com Tested-by: syzbot+641eec6b7af1f62f2b99@syzkaller.appspotmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3dfe2e1 commit 13a8f7b

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

io_uring/poll.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,12 +936,17 @@ int io_poll_remove(struct io_kiocb *req, unsigned int issue_flags)
936936

937937
ret2 = io_poll_add(preq, issue_flags & ~IO_URING_F_UNLOCKED);
938938
/* successfully updated, don't complete poll request */
939-
if (!ret2 || ret2 == -EIOCBQUEUED)
939+
if (ret2 == IOU_ISSUE_SKIP_COMPLETE)
940940
goto out;
941+
/* request completed as part of the update, complete it */
942+
else if (ret2 == IOU_COMPLETE)
943+
goto complete;
941944
}
942945

943-
req_set_fail(preq);
944946
io_req_set_res(preq, -ECANCELED, 0);
947+
complete:
948+
if (preq->cqe.res < 0)
949+
req_set_fail(preq);
945950
preq->io_task_work.func = io_req_task_complete;
946951
io_req_task_work_add(preq);
947952
out:

0 commit comments

Comments
 (0)