From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: [email protected],
[email protected]
Subject: [PATCH 1/1] io_uring: sanitise nr_pages for SQ/CQ
Date: Mon, 25 Nov 2024 23:22:24 +0000 [thread overview]
Message-ID: <9788f6363f9a7fc100f8f9fb7a1a6e11e014cd30.1732576266.git.asml.silence@gmail.com> (raw)
WARNING: CPU: 0 PID: 5834 at io_uring/memmap.c:144 io_pin_pages+0x149/0x180 io_uring/memmap.c:144
CPU: 0 UID: 0 PID: 5834 Comm: syz-executor825 Not tainted 6.12.0-next-20241118-syzkaller #0
Call Trace:
<TASK>
__io_uaddr_map+0xfb/0x2d0 io_uring/memmap.c:183
io_rings_map io_uring/io_uring.c:2611 [inline]
io_allocate_scq_urings+0x1c0/0x650 io_uring/io_uring.c:3470
io_uring_create+0x5b5/0xc00 io_uring/io_uring.c:3692
io_uring_setup io_uring/io_uring.c:3781 [inline]
...
</TASK>
Apparently there is a way to request a large enough CQ/SQ so that the
number of pages used doesn't fit into int. Even worse, then it's
truncated further to ushort. Limit them to the type size for now, but
it needs a better follow up.
Cc: [email protected]
Reported-by: [email protected]
Signed-off-by: Pavel Begunkov <[email protected]>
---
io_uring/io_uring.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index bfa93888f862..82d217cfdebc 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3482,7 +3482,7 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx,
size = rings_size(ctx->flags, p->sq_entries, p->cq_entries,
&sq_array_offset);
- if (size == SIZE_MAX)
+ if (size == SIZE_MAX || (PAGE_ALIGN(size) >> PAGE_SHIFT) > USHRT_MAX)
return -EOVERFLOW;
if (!(ctx->flags & IORING_SETUP_NO_MMAP))
@@ -3505,7 +3505,7 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx,
size = array_size(2 * sizeof(struct io_uring_sqe), p->sq_entries);
else
size = array_size(sizeof(struct io_uring_sqe), p->sq_entries);
- if (size == SIZE_MAX) {
+ if (size == SIZE_MAX || (PAGE_ALIGN(size) >> PAGE_SHIFT) > USHRT_MAX) {
io_rings_free(ctx);
return -EOVERFLOW;
}
--
2.47.1
next reply other threads:[~2024-11-25 23:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-25 23:22 Pavel Begunkov [this message]
2024-11-25 23:44 ` [PATCH 1/1] io_uring: sanitise nr_pages for SQ/CQ Pavel Begunkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9788f6363f9a7fc100f8f9fb7a1a6e11e014cd30.1732576266.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox