Skip to content

Commit 9148286

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix multishot accept request leaks
Having REQ_F_POLLED set doesn't guarantee that the request is executed as a multishot from the polling path. Fortunately for us, if the code thinks it's multishot issue when it's not, it can only ask to skip completion so leaking the request. Use issue_flags to mark multipoll issues. Cc: stable@vger.kernel.org Fixes: 390ed29 ("io_uring: add IORING_ACCEPT_MULTISHOT for accept") Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/7700ac57653f2823e30b34dc74da68678c0c5f13.1668710222.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 539bcb5 commit 9148286

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

include/linux/io_uring.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ enum io_uring_cmd_flags {
1616
IO_URING_F_SQE128 = 4,
1717
IO_URING_F_CQE32 = 8,
1818
IO_URING_F_IOPOLL = 16,
19+
20+
/* the request is executed from poll, it should not be freed */
21+
IO_URING_F_MULTISHOT = 32,
1922
};
2023

2124
struct io_uring_cmd {

io_uring/io_uring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,7 @@ int io_poll_issue(struct io_kiocb *req, bool *locked)
17681768
io_tw_lock(req->ctx, locked);
17691769
if (unlikely(req->task->flags & PF_EXITING))
17701770
return -EFAULT;
1771-
return io_issue_sqe(req, IO_URING_F_NONBLOCK);
1771+
return io_issue_sqe(req, IO_URING_F_NONBLOCK|IO_URING_F_MULTISHOT);
17721772
}
17731773

17741774
struct io_wq_work *io_wq_free_work(struct io_wq_work *work)

io_uring/io_uring.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ enum {
1717
IOU_ISSUE_SKIP_COMPLETE = -EIOCBQUEUED,
1818

1919
/*
20-
* Intended only when both REQ_F_POLLED and REQ_F_APOLL_MULTISHOT
21-
* are set to indicate to the poll runner that multishot should be
20+
* Intended only when both IO_URING_F_MULTISHOT is passed
21+
* to indicate to the poll runner that multishot should be
2222
* removed and the result is set on req->cqe.res.
2323
*/
2424
IOU_STOP_MULTISHOT = -ECANCELED,

io_uring/net.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,8 +1289,7 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags)
12891289
* return EAGAIN to arm the poll infra since it
12901290
* has already been done
12911291
*/
1292-
if ((req->flags & IO_APOLL_MULTI_POLLED) ==
1293-
IO_APOLL_MULTI_POLLED)
1292+
if (issue_flags & IO_URING_F_MULTISHOT)
12941293
ret = IOU_ISSUE_SKIP_COMPLETE;
12951294
return ret;
12961295
}
@@ -1315,9 +1314,7 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags)
13151314
goto retry;
13161315

13171316
io_req_set_res(req, ret, 0);
1318-
if (req->flags & REQ_F_POLLED)
1319-
return IOU_STOP_MULTISHOT;
1320-
return IOU_OK;
1317+
return (issue_flags & IO_URING_F_MULTISHOT) ? IOU_STOP_MULTISHOT : IOU_OK;
13211318
}
13221319

13231320
int io_socket_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)

0 commit comments

Comments
 (0)