io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] io_uring: fix sq array offset calculation
@ 2020-07-11  9:31 Dmitry Vyukov
  2020-07-11  9:37 ` Hristo Venev
  2020-07-11 15:15 ` Jens Axboe
  0 siblings, 2 replies; 14+ messages in thread
From: Dmitry Vyukov @ 2020-07-11  9:31 UTC (permalink / raw)
  To: axboe; +Cc: necip, Dmitry Vyukov, io-uring, Hristo Venev

rings_size() sets sq_offset to the total size of the rings
(the returned value which is used for memory allocation).
This is wrong: sq array should be located within the rings,
not after them. Set sq_offset to where it should be.

Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Cc: io-uring@vger.kernel.org
Cc: Hristo Venev <hristo@venev.name>
Fixes: 75b28affdd6a ("io_uring: allocate the two rings together")

---
This looks so wrong and yet io_uring works.
So I am either missing something very obvious here,
or io_uring worked only due to lucky side-effects
of rounding size to power-of-2 number of pages
(which gave it enough slack at the end),
maybe reading/writing some unrelated memory
with some sizes.
If I am wrong, please poke my nose into what I am not seeing.
Otherwise, we probably need to CC stable as well.
---
 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 ca8abde48b6c7..c4c3731ed41e9 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7063,6 +7063,9 @@ static unsigned long rings_size(unsigned sq_entries, unsigned cq_entries,
 		return SIZE_MAX;
 #endif
 
+	if (sq_offset)
+		*sq_offset = off;
+
 	sq_array_size = array_size(sizeof(u32), sq_entries);
 	if (sq_array_size == SIZE_MAX)
 		return SIZE_MAX;
@@ -7070,9 +7073,6 @@ static unsigned long rings_size(unsigned sq_entries, unsigned cq_entries,
 	if (check_add_overflow(off, sq_array_size, &off))
 		return SIZE_MAX;
 
-	if (sq_offset)
-		*sq_offset = off;
-
 	return off;
 }
 
-- 
2.27.0.383.g050319c2ae-goog


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

end of thread, other threads:[~2020-07-17 14:08 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-11  9:31 [PATCH] io_uring: fix sq array offset calculation Dmitry Vyukov
2020-07-11  9:37 ` Hristo Venev
2020-07-11 15:15 ` Jens Axboe
2020-07-11 15:31   ` Dmitry Vyukov
2020-07-11 15:36     ` Jens Axboe
2020-07-11 15:47       ` Jens Axboe
2020-07-11 15:52     ` Hristo Venev
2020-07-11 15:55       ` Jens Axboe
2020-07-11 15:56       ` Hristo Venev
2020-07-11 16:16       ` Dmitry Vyukov
2020-07-17 13:48         ` Dmitry Vyukov
2020-07-17 14:05           ` Jens Axboe
2020-07-17 14:08             ` Jens Axboe
2020-07-17 14:08             ` Dmitry Vyukov

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).