mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-07 21:53:44 +00:00
io_uring: fix racy IOPOLL completions
IOPOLL allows buffer remove/provide requests, but they doesn't synchronise by rules of IOPOLL, namely it have to hold uring_lock. Cc: <stable@vger.kernel.org> # 5.7+ Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
dad1b1242f
commit
31bff9a51b
@ -4152,11 +4152,17 @@ static int io_remove_buffers(struct io_kiocb *req, bool force_nonblock,
|
|||||||
head = idr_find(&ctx->io_buffer_idr, p->bgid);
|
head = idr_find(&ctx->io_buffer_idr, p->bgid);
|
||||||
if (head)
|
if (head)
|
||||||
ret = __io_remove_buffers(ctx, head, p->bgid, p->nbufs);
|
ret = __io_remove_buffers(ctx, head, p->bgid, p->nbufs);
|
||||||
|
|
||||||
io_ring_submit_lock(ctx, !force_nonblock);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
req_set_fail_links(req);
|
req_set_fail_links(req);
|
||||||
__io_req_complete(req, ret, 0, cs);
|
|
||||||
|
/* need to hold the lock to complete IOPOLL requests */
|
||||||
|
if (ctx->flags & IORING_SETUP_IOPOLL) {
|
||||||
|
__io_req_complete(req, ret, 0, cs);
|
||||||
|
io_ring_submit_unlock(ctx, !force_nonblock);
|
||||||
|
} else {
|
||||||
|
io_ring_submit_unlock(ctx, !force_nonblock);
|
||||||
|
__io_req_complete(req, ret, 0, cs);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4241,10 +4247,17 @@ static int io_provide_buffers(struct io_kiocb *req, bool force_nonblock,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
io_ring_submit_unlock(ctx, !force_nonblock);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
req_set_fail_links(req);
|
req_set_fail_links(req);
|
||||||
__io_req_complete(req, ret, 0, cs);
|
|
||||||
|
/* need to hold the lock to complete IOPOLL requests */
|
||||||
|
if (ctx->flags & IORING_SETUP_IOPOLL) {
|
||||||
|
__io_req_complete(req, ret, 0, cs);
|
||||||
|
io_ring_submit_unlock(ctx, !force_nonblock);
|
||||||
|
} else {
|
||||||
|
io_ring_submit_unlock(ctx, !force_nonblock);
|
||||||
|
__io_req_complete(req, ret, 0, cs);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user