Skip to content

Commit 68b11e8

Browse files
isilenceaxboe
authored andcommitted
io_uring: explicitly count entries for poll reqs
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: 18bceab ("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>
1 parent 1b48773 commit 68b11e8

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

fs/io_uring.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4802,6 +4802,7 @@ IO_NETOP_FN(recv);
48024802
struct io_poll_table {
48034803
struct poll_table_struct pt;
48044804
struct io_kiocb *req;
4805+
int nr_entries;
48054806
int error;
48064807
};
48074808

@@ -4995,11 +4996,11 @@ static void __io_queue_proc(struct io_poll_iocb *poll, struct io_poll_table *pt,
49954996
struct io_kiocb *req = pt->req;
49964997

49974998
/*
4998-
* If poll->head is already set, it's because the file being polled
4999-
* uses multiple waitqueues for poll handling (eg one for read, one
5000-
* for write). Setup a separate io_poll_iocb if this happens.
4999+
* The file being polled uses multiple waitqueues for poll handling
5000+
* (e.g. one for read, one for write). Setup a separate io_poll_iocb
5001+
* if this happens.
50015002
*/
5002-
if (unlikely(poll->head)) {
5003+
if (unlikely(pt->nr_entries)) {
50035004
struct io_poll_iocb *poll_one = poll;
50045005

50055006
/* already have a 2nd entry, fail a third attempt */
@@ -5027,7 +5028,7 @@ static void __io_queue_proc(struct io_poll_iocb *poll, struct io_poll_table *pt,
50275028
*poll_ptr = poll;
50285029
}
50295030

5030-
pt->error = 0;
5031+
pt->nr_entries++;
50315032
poll->head = head;
50325033

50335034
if (poll->events & EPOLLEXCLUSIVE)
@@ -5104,9 +5105,12 @@ static __poll_t __io_arm_poll_handler(struct io_kiocb *req,
51045105

51055106
ipt->pt._key = mask;
51065107
ipt->req = req;
5107-
ipt->error = -EINVAL;
5108+
ipt->error = 0;
5109+
ipt->nr_entries = 0;
51085110

51095111
mask = vfs_poll(req->file, &ipt->pt) & poll->events;
5112+
if (unlikely(!ipt->nr_entries) && !ipt->error)
5113+
ipt->error = -EINVAL;
51105114

51115115
spin_lock_irq(&ctx->completion_lock);
51125116
if (likely(poll->head)) {

0 commit comments

Comments
 (0)