public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH for-5.6] io_uring: fix use-after-free by io_cleanup_req()
@ 2020-02-18 21:19 Pavel Begunkov
  2020-02-18 21:28 ` Pavel Begunkov
  2020-02-19  0:13 ` Jens Axboe
  0 siblings, 2 replies; 4+ messages in thread
From: Pavel Begunkov @ 2020-02-18 21:19 UTC (permalink / raw)
  To: Jens Axboe, io-uring

io_cleanup_req() should be called before req->io is freed, and so
shouldn't be after __io_free_req() -> __io_req_aux_free(). Also,
it will be ignored for in io_free_req_many(), which use
__io_req_aux_free().

Place cleanup_req() into __io_req_aux_free().

Fixes: 99bc4c38537d774 ("io_uring: fix iovec leaks")
Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 11627818104e..c39a81f8f83d 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1296,6 +1296,9 @@ static void __io_req_aux_free(struct io_kiocb *req)
 {
 	struct io_ring_ctx *ctx = req->ctx;
 
+	if (req->flags & REQ_F_NEED_CLEANUP)
+		io_cleanup_req(req);
+
 	kfree(req->io);
 	if (req->file)
 		io_put_file(ctx, req->file, (req->flags & REQ_F_FIXED_FILE));
@@ -1307,9 +1310,6 @@ static void __io_free_req(struct io_kiocb *req)
 {
 	__io_req_aux_free(req);
 
-	if (req->flags & REQ_F_NEED_CLEANUP)
-		io_cleanup_req(req);
-
 	if (req->flags & REQ_F_INFLIGHT) {
 		struct io_ring_ctx *ctx = req->ctx;
 		unsigned long flags;
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-19 10:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-18 21:19 [PATCH for-5.6] io_uring: fix use-after-free by io_cleanup_req() Pavel Begunkov
2020-02-18 21:28 ` Pavel Begunkov
2020-02-19  0:13 ` Jens Axboe
2020-02-19 10:03   ` Pavel Begunkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox