[SRU][J][PATCH 1/1] io_uring: check for overflows in io_pin_pages

Cengiz Can cengiz.can at canonical.com
Mon Sep 7 16:51:22 UTC 2026


From: Pavel Begunkov <asml.silence at gmail.com>

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>

io_pin_pages()'s uaddr parameter came directly from the user and can be
garbage. Don't just add size to it as it can overflow.

Cc: stable at vger.kernel.org
Reported-by: syzbot+2159cbb522b02847c053 at syzkaller.appspotmail.com
Signed-off-by: Pavel Begunkov <asml.silence at gmail.com>
Link: https://lore.kernel.org/r/1b7520ddb168e1d537d64be47414a0629d0d8f8f.1732581026.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe at kernel.dk>
(backported from commit 0c0a4eae26ac78379d0c1db053de168a8febc6c9)
[bot_kybele: This tree has no io_uring/memmap.c or io_pin_pages(); the analogue
 is the inline page-pinning in io_sqe_buffer_register() in io_uring.c, so the
 check_add_overflow guards were applied to its "end = ubuf + iov_len +
 PAGE_SIZE-1" computation, returning via ret=-EOVERFLOW/goto done (the tree's
 teardown path) instead of ERR_PTR, and the spurious 3-way-created memmap.c was
 removed.]
CVE-2024-53187
Assisted-by: kybele:claude-opus-4.8
Signed-off-by: Cengiz Can <cengiz.can at canonical.com>
---
 io_uring/io_uring.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 5b441dff650d..b9fbd5bb85a1 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -9137,13 +9137,22 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,
 	}
 
 	ubuf = (unsigned long) iov->iov_base;
-	end = (ubuf + iov->iov_len + PAGE_SIZE - 1) >> PAGE_SHIFT;
-	start = ubuf >> PAGE_SHIFT;
-	nr_pages = end - start;
 
 	*pimu = NULL;
 	ret = -ENOMEM;
 
+	if (check_add_overflow(ubuf, iov->iov_len, &end)) {
+		ret = -EOVERFLOW;
+		goto done;
+	}
+	if (check_add_overflow(end, PAGE_SIZE - 1, &end)) {
+		ret = -EOVERFLOW;
+		goto done;
+	}
+	end = end >> PAGE_SHIFT;
+	start = ubuf >> PAGE_SHIFT;
+	nr_pages = end - start;
+
 	pages = kvmalloc_array(nr_pages, sizeof(struct page *), GFP_KERNEL);
 	if (!pages)
 		goto done;
-- 
2.53.0




More information about the kernel-team mailing list