Skip to content

Commit 68685fa

Browse files
isilenceaxboe
authored andcommitted
io_uring: fortify io_pin_pages with a warning
We're a bit too frivolous with types of nr_pages arguments, converting it to long and back to int, passing an unsigned int pointer as an int pointer and so on. Shouldn't cause any problem but should be carefully reviewed, but until then let's add a WARN_ON_ONCE check to be more confident callers don't pass poorely checked arguents. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/d48e0c097cbd90fb47acaddb6c247596510d8cfc.1731689588.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 56cec28 commit 68685fa

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

io_uring/memmap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ struct page **io_pin_pages(unsigned long uaddr, unsigned long len, int *npages)
140140
nr_pages = end - start;
141141
if (WARN_ON_ONCE(!nr_pages))
142142
return ERR_PTR(-EINVAL);
143+
if (WARN_ON_ONCE(nr_pages > INT_MAX))
144+
return ERR_PTR(-EOVERFLOW);
143145

144146
pages = kvmalloc_array(nr_pages, sizeof(struct page *), GFP_KERNEL);
145147
if (!pages)

0 commit comments

Comments
 (0)