public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH] io_uring: Fix LINK_TIMEOUT checks
Date: Fri, 15 Nov 2019 00:20:48 +0300	[thread overview]
Message-ID: <9a5eef46f7ed9f52f8de67d314651cd4a4234572.1573766402.git.asml.silence@gmail.com> (raw)

If IORING_OP_LINK_TIMEOUT request is a head of a link or an individual
request, pass it further through the submission path, where it will
eventually fail in __io_submit_sqe(). So respecting links and drains.

The case, which is really need to be checked, is if a
IORING_OP_LINK_TIMEOUT request is 3rd or later in a link, that is
invalid from the user API perspective (judging by the code). Moreover,
put/free and friends will try to io_link_cancel_timeout() such request,
even though it wasn't initialised.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 55f8b1d378df..fd2ba35f53e3 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2952,6 +2952,12 @@ static void io_submit_sqe(struct io_kiocb *req, struct io_submit_state *state,
 	if (*link) {
 		struct io_kiocb *prev = *link;
 
+		if (unlikely(READ_ONCE(s->sqe->opcode) == IORING_OP_LINK_TIMEOUT
+			&& !list_empty(&prev->link_list))) {
+			ret = -EINVAL;
+			goto err_req;
+		}
+
 		sqe_copy = kmemdup(s->sqe, sizeof(*sqe_copy), GFP_KERNEL);
 		if (!sqe_copy) {
 			ret = -EAGAIN;
@@ -2966,10 +2972,6 @@ static void io_submit_sqe(struct io_kiocb *req, struct io_submit_state *state,
 
 		INIT_LIST_HEAD(&req->link_list);
 		*link = req;
-	} else if (READ_ONCE(s->sqe->opcode) == IORING_OP_LINK_TIMEOUT) {
-		/* Only valid as a linked SQE */
-		ret = -EINVAL;
-		goto err_req;
 	} else {
 		io_queue_sqe(req);
 	}
-- 
2.24.0


             reply	other threads:[~2019-11-14 21:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-14 21:20 Pavel Begunkov [this message]
2019-11-14 21:25 ` [PATCH] io_uring: Fix LINK_TIMEOUT checks Jens Axboe
2019-11-14 21:31   ` Pavel Begunkov
2019-11-15  0:12   ` Jens Axboe
2019-11-15  2:36     ` Jens Axboe
2019-11-15  3:22       ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9a5eef46f7ed9f52f8de67d314651cd4a4234572.1573766402.git.asml.silence@gmail.com \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox