Skip to content
/ linux Public

Commit 0f4ce79

Browse files
axboegregkh
authored andcommitted
io_uring/poll: fix multishot recv missing EOF on wakeup race
commit a68ed2d upstream. When a socket send and shutdown() happen back-to-back, both fire wake-ups before the receiver's task_work has a chance to run. The first wake gets poll ownership (poll_refs=1), and the second bumps it to 2. When io_poll_check_events() runs, it calls io_poll_issue() which does a recv that reads the data and returns IOU_RETRY. The loop then drains all accumulated refs (atomic_sub_return(2) -> 0) and exits, even though only the first event was consumed. Since the shutdown is a persistent state change, no further wakeups will happen, and the multishot recv can hang forever. Check specifically for HUP in the poll loop, and ensure that another loop is done to check for status if more than a single poll activation is pending. This ensures we don't lose the shutdown event. Cc: stable@vger.kernel.org Fixes: dbc2564 ("io_uring: let fast poll support multishot") Reported-by: Francis Brosseau <francis@malagauche.com> Link: axboe/liburing#1549 Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ee312bb commit 0f4ce79

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

io_uring/poll.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw)
254254
atomic_andnot(IO_POLL_RETRY_FLAG, &req->poll_refs);
255255
v &= ~IO_POLL_RETRY_FLAG;
256256
}
257+
v &= IO_POLL_REF_MASK;
257258
}
258259

259260
/* the mask was stashed in __io_poll_execute */
@@ -286,8 +287,13 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw)
286287
return IOU_POLL_REMOVE_POLL_USE_RES;
287288
}
288289
} else {
289-
int ret = io_poll_issue(req, tw);
290+
int ret;
290291

292+
/* multiple refs and HUP, ensure we loop once more */
293+
if ((req->cqe.res & (POLLHUP | POLLRDHUP)) && v != 1)
294+
v--;
295+
296+
ret = io_poll_issue(req, tw);
291297
if (ret == IOU_COMPLETE)
292298
return IOU_POLL_REMOVE_POLL_USE_RES;
293299
else if (ret == IOU_REQUEUE)
@@ -303,7 +309,6 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw)
303309
* Release all references, retry if someone tried to restart
304310
* task_work while we were executing it.
305311
*/
306-
v &= IO_POLL_REF_MASK;
307312
} while (atomic_sub_return(v, &req->poll_refs) & IO_POLL_REF_MASK);
308313

309314
io_napi_add(req);

0 commit comments

Comments
 (0)