Commit 8fa77f4d authored by Pavel Begunkov's avatar Pavel Begunkov Committed by sanglipeng
Browse files

io_uring: fix double poll leak on repolling

stable inclusion
from stable-v5.10.165
commit c1a279d79e313bd9b0ed31025edc68394bfc40ab
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7T7G4

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=c1a279d79e313bd9b0ed31025edc68394bfc40ab



--------------------------------

commit c0737fa9 upstream.

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: 10c87333 ("io_uring: allow re-poll if we made progress")
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/fee2452494222ecc7f1f88c8fb659baef971414a.1655852245.git.asml.silence@gmail.com


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarsanglipeng <sanglipeng1@jd.com>
parent 302ac77b
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -5754,10 +5754,12 @@ static int io_arm_poll_handler(struct io_kiocb *req)
		mask |= POLLOUT | POLLWRNORM;
	}

	if (req->flags & REQ_F_POLLED)
	if (req->flags & REQ_F_POLLED) {
		apoll = req->apoll;
	else
		kfree(apoll->double_poll);
	} else {
		apoll = kmalloc(sizeof(*apoll), GFP_ATOMIC);
	}
	if (unlikely(!apoll))
		return IO_APOLL_ABORTED;
	apoll->double_poll = NULL;