Skip to content

Commit 0c0a4ea

Browse files
isilenceaxboe
authored andcommitted
io_uring: check for overflows in io_pin_pages
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@vger.kernel.org Reported-by: syzbot+2159cbb522b02847c053@syzkaller.appspotmail.com Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/1b7520ddb168e1d537d64be47414a0629d0d8f8f.1732581026.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ee11657 commit 0c0a4ea

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

io_uring/memmap.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,12 @@ struct page **io_pin_pages(unsigned long uaddr, unsigned long len, int *npages)
136136
struct page **pages;
137137
int ret;
138138

139-
end = (uaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
139+
if (check_add_overflow(uaddr, len, &end))
140+
return ERR_PTR(-EOVERFLOW);
141+
if (check_add_overflow(end, PAGE_SIZE - 1, &end))
142+
return ERR_PTR(-EOVERFLOW);
143+
144+
end = end >> PAGE_SHIFT;
140145
start = uaddr >> PAGE_SHIFT;
141146
nr_pages = end - start;
142147
if (WARN_ON_ONCE(!nr_pages))

0 commit comments

Comments
 (0)