io_uring: explicitly count entries for poll reqs
commit 68b11e8b1562986c134764433af64e97d30c9fc0 upstream.
If __io_queue_proc() fails to add a second poll entry, e.g. kmalloc()
failed, but it goes on with a third waitqueue, it may succeed and
overwrite the error status. Count the number of poll entries we added,
so we can set pt->error to zero at the beginning and find out when the
mentioned scenario happens.
Cc: stable@vger.kernel.org
Fixes: 18bceab101
("io_uring: allow POLL_ADD with double poll_wait() users")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/9d6b9e561f88bcc0163623b74a76c39f712151c3.1626774457.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
1077e2b152
commit
9eef902915
@@ -4916,6 +4916,7 @@ static int io_connect(struct io_kiocb *req, bool force_nonblock,
|
|||||||
struct io_poll_table {
|
struct io_poll_table {
|
||||||
struct poll_table_struct pt;
|
struct poll_table_struct pt;
|
||||||
struct io_kiocb *req;
|
struct io_kiocb *req;
|
||||||
|
int nr_entries;
|
||||||
int error;
|
int error;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -5098,11 +5099,11 @@ static void __io_queue_proc(struct io_poll_iocb *poll, struct io_poll_table *pt,
|
|||||||
struct io_kiocb *req = pt->req;
|
struct io_kiocb *req = pt->req;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If poll->head is already set, it's because the file being polled
|
* The file being polled uses multiple waitqueues for poll handling
|
||||||
* uses multiple waitqueues for poll handling (eg one for read, one
|
* (e.g. one for read, one for write). Setup a separate io_poll_iocb
|
||||||
* for write). Setup a separate io_poll_iocb if this happens.
|
* if this happens.
|
||||||
*/
|
*/
|
||||||
if (unlikely(poll->head)) {
|
if (unlikely(pt->nr_entries)) {
|
||||||
struct io_poll_iocb *poll_one = poll;
|
struct io_poll_iocb *poll_one = poll;
|
||||||
|
|
||||||
/* already have a 2nd entry, fail a third attempt */
|
/* already have a 2nd entry, fail a third attempt */
|
||||||
@@ -5124,7 +5125,7 @@ static void __io_queue_proc(struct io_poll_iocb *poll, struct io_poll_table *pt,
|
|||||||
*poll_ptr = poll;
|
*poll_ptr = poll;
|
||||||
}
|
}
|
||||||
|
|
||||||
pt->error = 0;
|
pt->nr_entries++;
|
||||||
poll->head = head;
|
poll->head = head;
|
||||||
|
|
||||||
if (poll->events & EPOLLEXCLUSIVE)
|
if (poll->events & EPOLLEXCLUSIVE)
|
||||||
@@ -5210,9 +5211,12 @@ static __poll_t __io_arm_poll_handler(struct io_kiocb *req,
|
|||||||
|
|
||||||
ipt->pt._key = mask;
|
ipt->pt._key = mask;
|
||||||
ipt->req = req;
|
ipt->req = req;
|
||||||
ipt->error = -EINVAL;
|
ipt->error = 0;
|
||||||
|
ipt->nr_entries = 0;
|
||||||
|
|
||||||
mask = vfs_poll(req->file, &ipt->pt) & poll->events;
|
mask = vfs_poll(req->file, &ipt->pt) & poll->events;
|
||||||
|
if (unlikely(!ipt->nr_entries) && !ipt->error)
|
||||||
|
ipt->error = -EINVAL;
|
||||||
|
|
||||||
spin_lock_irq(&ctx->completion_lock);
|
spin_lock_irq(&ctx->completion_lock);
|
||||||
if (likely(poll->head)) {
|
if (likely(poll->head)) {
|
||||||
|
Reference in New Issue
Block a user