From: Xiaoguang Wang <[email protected]>
To: io-uring <[email protected]>
Cc: "[email protected]" <[email protected]>,
Pavel Begunkov <[email protected]>,
joseph qi <[email protected]>
Subject: race between REQ_F_NEED_CLEANUP and io_complete_rw_iopoll,io_complete_rw
Date: Tue, 16 Jun 2020 00:02:36 +0800 [thread overview]
Message-ID: <[email protected]> (raw)
hi,
After looking into more codes, I guess there will be more races between
REQ_F_NEED_CLEANUP and io_complete_rw_iopoll/io_complete_rw.
In the end of io_read() or io_write(), there are such below codes:
req->flags &= ~REQ_F_NEED_CLEANUP;
kfree(iovec);
return ret;
When "req->flags &= ~REQ_F_NEED_CLEANUP" is executed, io request may also
have been completed, then there will be many req->flags modifications called
by io_complete_rw_iopoll() or io_complete_rw(), such as req_set_fail_links(req),
req->flags |= REQ_F_OVERFLOW in __io_cqring_fill_event(). All these races can
introduce severe bugs.
I wonder below patch whether can fix these races:
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 13e24a6137d5..3bab6b414864 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2654,8 +2654,8 @@ static int io_read(struct io_kiocb *req, bool force_nonblock)
}
}
out_free:
- kfree(iovec);
- req->flags &= ~REQ_F_NEED_CLEANUP;
+ if (!(req->flags & REQ_F_NEED_CLEANUP))
+ kfree(iovec);
return ret;
}
If REQ_F_NEED_CLEANUP is set, we always make __io_req_aux_free() do the cleanup work.
Regards,
Xiaoguang Wang
reply other threads:[~2020-06-15 16:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4e043e31-f993-b230-b394-447af6b0a37d@linux.alibaba.com \
[email protected] \
[email protected] \
[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