public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH 1/1] io_uring: check for overflows in io_pin_pages
@ 2024-11-26  0:34 Pavel Begunkov
  2024-11-26 15:00 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Begunkov @ 2024-11-26  0:34 UTC (permalink / raw)
  To: io-uring; +Cc: asml.silence, syzbot+2159cbb522b02847c053

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: [email protected]
Reported-by: [email protected]
Signed-off-by: Pavel Begunkov <[email protected]>
---
 io_uring/memmap.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/io_uring/memmap.c b/io_uring/memmap.c
index 2b6be273e893..57de9bccbf50 100644
--- a/io_uring/memmap.c
+++ b/io_uring/memmap.c
@@ -138,7 +138,12 @@ struct page **io_pin_pages(unsigned long uaddr, unsigned long len, int *npages)
 	struct page **pages;
 	int ret;
 
-	end = (uaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+	if (check_add_overflow(uaddr, len, &end))
+		return ERR_PTR(-EOVERFLOW);
+	if (check_add_overflow(end, PAGE_SIZE - 1, &end))
+		return ERR_PTR(-EOVERFLOW);
+
+	end = end >> PAGE_SHIFT;
 	start = uaddr >> PAGE_SHIFT;
 	nr_pages = end - start;
 	if (WARN_ON_ONCE(!nr_pages))
-- 
2.47.1


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

* Re: [PATCH 1/1] io_uring: check for overflows in io_pin_pages
  2024-11-26  0:34 [PATCH 1/1] io_uring: check for overflows in io_pin_pages Pavel Begunkov
@ 2024-11-26 15:00 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2024-11-26 15:00 UTC (permalink / raw)
  To: io-uring, Pavel Begunkov; +Cc: syzbot+2159cbb522b02847c053


On Tue, 26 Nov 2024 00:34:18 +0000, Pavel Begunkov wrote:
> 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>
> 
> [...]

Applied, thanks!

[1/1] io_uring: check for overflows in io_pin_pages
      commit: 0c0a4eae26ac78379d0c1db053de168a8febc6c9

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2024-11-26 15:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-26  0:34 [PATCH 1/1] io_uring: check for overflows in io_pin_pages Pavel Begunkov
2024-11-26 15:00 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox