public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH 2/5] io_uring: fix feeding io-wq with uninit reqs
Date: Sat, 27 Jun 2020 14:04:56 +0300	[thread overview]
Message-ID: <8ba05db0dc37f05c64ad5814ddeaed4a462c3ae5.1593253742.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

io_steal_work() can't be sure that @nxt have req->work
properly set, so we can't pass it to io-wq as is.

A dirty quick fix -- drag it through io_req_task_queue(),
and always return NULL from io_steal_work().

e.g.
[   50.770161] BUG: kernel NULL pointer dereference, address: 00000000
[   50.770164] #PF: supervisor write access in kernel mode
[   50.770164] #PF: error_code(0x0002) - not-present page
[   50.770168] CPU: 1 PID: 1448 Comm: io_wqe_worker-0 Tainted: G
	I       5.8.0-rc2-00035-g2237d76530eb-dirty #494
[   50.770172] RIP: 0010:override_creds+0x19/0x30
...
[   50.770183]  io_worker_handle_work+0x25c/0x430
[   50.770185]  io_wqe_worker+0x2a0/0x350
[   50.770190]  kthread+0x136/0x180
[   50.770194]  ret_from_fork+0x22/0x30

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

diff --git a/fs/io_uring.c b/fs/io_uring.c
index e10aeae8cc52..b577d6f50cbc 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1791,7 +1791,7 @@ static void io_put_req(struct io_kiocb *req)
 
 static struct io_wq_work *io_steal_work(struct io_kiocb *req)
 {
-	struct io_kiocb *link, *nxt = NULL;
+	struct io_kiocb *nxt = NULL;
 
 	/*
 	 * A ref is owned by io-wq in which context we're. So, if that's the
@@ -1808,10 +1808,15 @@ static struct io_wq_work *io_steal_work(struct io_kiocb *req)
 	if ((nxt->flags & REQ_F_ISREG) && io_op_defs[nxt->opcode].hash_reg_file)
 		io_wq_hash_work(&nxt->work, file_inode(nxt->file));
 
-	link = io_prep_linked_timeout(nxt);
-	if (link)
-		nxt->flags |= REQ_F_QUEUE_TIMEOUT;
-	return &nxt->work;
+	io_req_task_queue(nxt);
+	/*
+	 * If we're going to return actual work, here should be timeout prep:
+	 *
+	 * link = io_prep_linked_timeout(nxt);
+	 * if (link)
+	 *	nxt->flags |= REQ_F_QUEUE_TIMEOUT;
+	 */
+	return NULL;
 }
 
 /*
-- 
2.24.0


  parent reply	other threads:[~2020-06-27 11:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-27 11:04 [PATCH 0/5] "task_work for links" fixes Pavel Begunkov
2020-06-27 11:04 ` [PATCH 1/5] io_uring: fix punting req w/o grabbed env Pavel Begunkov
2020-06-27 11:04 ` Pavel Begunkov [this message]
2020-06-27 11:04 ` [PATCH 3/5] io_uring: don't mark link's head for_async Pavel Begunkov
2020-06-27 11:04 ` [PATCH 4/5] io_uring: fix missing io_grab_files() Pavel Begunkov
2020-06-27 11:04 ` [PATCH 5/5] io_ring: fix req->work corruption Pavel Begunkov
2020-06-28 13:49 ` [PATCH 0/5] "task_work for links" fixes Jens Axboe
2020-06-28 14:46   ` Pavel Begunkov
2020-06-29 10:21     ` Pavel Begunkov
2020-06-29 15:52       ` Jens Axboe
2020-06-29 16:32         ` Pavel Begunkov
2020-06-29 16:37           ` 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=8ba05db0dc37f05c64ad5814ddeaed4a462c3ae5.1593253742.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