diff mbox series

[5.19,3/3] io_uring: fix double poll leak on repolling

Message ID fee2452494222ecc7f1f88c8fb659baef971414a.1655852245.git.asml.silence@gmail.com (mailing list archive)
State New
Headers show
Series poll fixes | expand

Commit Message

Pavel Begunkov June 21, 2022, 11 p.m. UTC
We have re-polling for partial IO, so a request can be polled twice. If
it used two poll entries the first time then on the second
io_arm_poll_handler() it will find the old apoll entry and NULL
kmalloc()'ed second entry, i.e. apoll->double_poll, so leaking it.

Fixes: 10c873334feba ("io_uring: allow re-poll if we made progress")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/io_uring.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Jens Axboe June 22, 2022, 3:34 a.m. UTC | #1
On 6/21/22 5:00 PM, Pavel Begunkov wrote:
> We have re-polling for partial IO, so a request can be polled twice. If
> it used two poll entries the first time then on the second
> io_arm_poll_handler() it will find the old apoll entry and NULL
> kmalloc()'ed second entry, i.e. apoll->double_poll, so leaking it.
> 
> Fixes: 10c873334feba ("io_uring: allow re-poll if we made progress")
> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
> ---
>  fs/io_uring.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index cb719a53b8bd..5c95755619e2 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -7208,6 +7208,7 @@ static int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags)
>  		mask |= EPOLLEXCLUSIVE;
>  	if (req->flags & REQ_F_POLLED) {
>  		apoll = req->apoll;
> +		kfree(apoll->double_poll);
>  	} else if (!(issue_flags & IO_URING_F_UNLOCKED) &&
>  		   !list_empty(&ctx->apoll_cache)) {
>  		apoll = list_first_entry(&ctx->apoll_cache, struct async_poll,

Looks good, my only question was on whether we should clear ->double_poll
here, but we do that right below so all's good.
diff mbox series

Patch

diff --git a/fs/io_uring.c b/fs/io_uring.c
index cb719a53b8bd..5c95755619e2 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7208,6 +7208,7 @@  static int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags)
 		mask |= EPOLLEXCLUSIVE;
 	if (req->flags & REQ_F_POLLED) {
 		apoll = req->apoll;
+		kfree(apoll->double_poll);
 	} else if (!(issue_flags & IO_URING_F_UNLOCKED) &&
 		   !list_empty(&ctx->apoll_cache)) {
 		apoll = list_first_entry(&ctx->apoll_cache, struct async_poll,