Skip to content

Commit b7c6d08

Browse files
isilencegregkh
authored andcommitted
io_uring/net: fix io_req_post_cqe abuse by send bundle
commit 6889ae1 upstream. [ 114.987980][ T5313] WARNING: CPU: 6 PID: 5313 at io_uring/io_uring.c:872 io_req_post_cqe+0x12e/0x4f0 [ 114.991597][ T5313] RIP: 0010:io_req_post_cqe+0x12e/0x4f0 [ 115.001880][ T5313] Call Trace: [ 115.002222][ T5313] <TASK> [ 115.007813][ T5313] io_send+0x4fe/0x10f0 [ 115.009317][ T5313] io_issue_sqe+0x1a6/0x1740 [ 115.012094][ T5313] io_wq_submit_work+0x38b/0xed0 [ 115.013223][ T5313] io_worker_handle_work+0x62a/0x1600 [ 115.013876][ T5313] io_wq_worker+0x34f/0xdf0 As the comment states, io_req_post_cqe() should only be used by multishot requests, i.e. REQ_F_APOLL_MULTISHOT, which bundled sends are not. Add a flag signifying whether a request wants to post multiple CQEs. Eventually REQ_F_APOLL_MULTISHOT should imply the new flag, but that's left out for simplicity. Cc: stable@vger.kernel.org Fixes: a05d1f6 ("io_uring/net: support bundles for send") Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/8b611dbb54d1cd47a88681f5d38c84d0c02bc563.1743067183.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0828d6e commit b7c6d08

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

include/linux/io_uring_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ enum {
457457
REQ_F_SKIP_LINK_CQES_BIT,
458458
REQ_F_SINGLE_POLL_BIT,
459459
REQ_F_DOUBLE_POLL_BIT,
460+
REQ_F_MULTISHOT_BIT,
460461
REQ_F_APOLL_MULTISHOT_BIT,
461462
REQ_F_CLEAR_POLLIN_BIT,
462463
REQ_F_HASH_LOCKED_BIT,
@@ -530,6 +531,8 @@ enum {
530531
REQ_F_SINGLE_POLL = IO_REQ_FLAG(REQ_F_SINGLE_POLL_BIT),
531532
/* double poll may active */
532533
REQ_F_DOUBLE_POLL = IO_REQ_FLAG(REQ_F_DOUBLE_POLL_BIT),
534+
/* request posts multiple completions, should be set at prep time */
535+
REQ_F_MULTISHOT = IO_REQ_FLAG(REQ_F_MULTISHOT_BIT),
533536
/* fast poll multishot mode */
534537
REQ_F_APOLL_MULTISHOT = IO_REQ_FLAG(REQ_F_APOLL_MULTISHOT_BIT),
535538
/* recvmsg special flag, clear EPOLLIN */

io_uring/io_uring.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ void io_wq_submit_work(struct io_wq_work *work)
18211821
* Don't allow any multishot execution from io-wq. It's more restrictive
18221822
* than necessary and also cleaner.
18231823
*/
1824-
if (req->flags & REQ_F_APOLL_MULTISHOT) {
1824+
if (req->flags & (REQ_F_MULTISHOT|REQ_F_APOLL_MULTISHOT)) {
18251825
err = -EBADFD;
18261826
if (!io_file_can_poll(req))
18271827
goto fail;
@@ -1832,7 +1832,7 @@ void io_wq_submit_work(struct io_wq_work *work)
18321832
goto fail;
18331833
return;
18341834
} else {
1835-
req->flags &= ~REQ_F_APOLL_MULTISHOT;
1835+
req->flags &= ~(REQ_F_APOLL_MULTISHOT|REQ_F_MULTISHOT);
18361836
}
18371837
}
18381838

io_uring/net.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
435435
sr->msg_flags |= MSG_WAITALL;
436436
sr->buf_group = req->buf_index;
437437
req->buf_list = NULL;
438+
req->flags |= REQ_F_MULTISHOT;
438439
}
439440

440441
#ifdef CONFIG_COMPAT

0 commit comments

Comments
 (0)