io_uring: fix sq array offset calculation
authorDmitry Vyukov <dvyukov@google.com>
Sat, 11 Jul 2020 09:31:11 +0000 (11:31 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 24 Jul 2020 18:55:44 +0000 (12:55 -0600)
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.

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

index ff3851d40df4fea72c4eb5d7643326d20db32d8f..ca932fb3c67d8828095b2d08e435798c3ec91c51 100644 (file)
@@ -7416,6 +7416,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;
@@ -7423,9 +7426,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;
 }