Skip to content

Commit fca5343

Browse files
isilencegregkh
authored andcommitted
io_uring: remove double poll entry on arm failure
commit 46fee9a upstream. __io_queue_proc() can enqueue both poll entries and still fail afterwards, so the callers trying to cancel it should also try to remove the second poll entry (if any). For example, it may leave the request alive referencing a io_uring context but not accessible for cancellation: [ 282.599913][ T1620] task:iou-sqp-23145 state:D stack:28720 pid:23155 ppid: 8844 flags:0x00004004 [ 282.609927][ T1620] Call Trace: [ 282.613711][ T1620] __schedule+0x93a/0x26f0 [ 282.634647][ T1620] schedule+0xd3/0x270 [ 282.638874][ T1620] io_uring_cancel_generic+0x54d/0x890 [ 282.660346][ T1620] io_sq_thread+0xaac/0x1250 [ 282.696394][ T1620] ret_from_fork+0x1f/0x30 Cc: [email protected] Fixes: 18bceab ("io_uring: allow POLL_ADD with double poll_wait() users") Reported-and-tested-by: [email protected] Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/0ec1228fc5eda4cb524eeda857da8efdc43c331c.1626774457.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9eef902 commit fca5343

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/io_uring.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5219,6 +5219,8 @@ static __poll_t __io_arm_poll_handler(struct io_kiocb *req,
52195219
ipt->error = -EINVAL;
52205220

52215221
spin_lock_irq(&ctx->completion_lock);
5222+
if (ipt->error)
5223+
io_poll_remove_double(req);
52225224
if (likely(poll->head)) {
52235225
spin_lock(&poll->head->lock);
52245226
if (unlikely(list_empty(&poll->wait.entry))) {

0 commit comments

Comments
 (0)