io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* race between REQ_F_NEED_CLEANUP and io_complete_rw_iopoll,io_complete_rw
@ 2020-06-15 16:02 Xiaoguang Wang
  0 siblings, 0 replies; only message in thread
From: Xiaoguang Wang @ 2020-06-15 16:02 UTC (permalink / raw)
  To: io-uring; +Cc: axboe, Pavel Begunkov, joseph qi

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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-15 16:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15 16:02 race between REQ_F_NEED_CLEANUP and io_complete_rw_iopoll,io_complete_rw Xiaoguang Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).