[PATCH 5.3 139/197] io_uring: Fix race for sqes with userspace
From: Greg Kroah-Hartman
Date: Sun Oct 27 2019 - 17:27:08 EST
From: Pavel Begunkov <asml.silence@xxxxxxxxx>
[ Upstream commit 935d1e45908afb8853c497f2c2bbbb685dec51dc ]
io_ring_submit() finalises with
1. io_commit_sqring(), which releases sqes to the userspace
2. Then calls to io_queue_link_head(), accessing released head's sqe
Reorder them.
Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx>
Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
fs/io_uring.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 518042cc6628b..d447f43d64a24 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2488,13 +2488,14 @@ static int io_ring_submit(struct io_ring_ctx *ctx, unsigned int to_submit)
submit++;
io_submit_sqe(ctx, &s, statep, &link);
}
- io_commit_sqring(ctx);
if (link)
io_queue_sqe(ctx, link, &link->submit);
if (statep)
io_submit_state_end(statep);
+ io_commit_sqring(ctx);
+
return submit;
}
--
2.20.1