Skip to content

Commit 669b0cb

Browse files
Dan Carpenterakpm00
authored andcommitted
fs/proc/task_mmu: prevent integer overflow in pagemap_scan_get_args()
The "arg->vec_len" variable is a u64 that comes from the user at the start of the function. The "arg->vec_len * sizeof(struct page_region))" multiplication can lead to integer wrapping. Use size_mul() to avoid that. Also the size_add/mul() functions work on unsigned long so for 32bit systems we need to ensure that "arg->vec_len" fits in an unsigned long. Link: https://lkml.kernel.org/r/[email protected] Fixes: 52526ca ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs") Signed-off-by: Dan Carpenter <[email protected]> Cc: Andrei Vagin <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Michał Mirosław <[email protected]> Cc: Muhammad Usama Anjum <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Peter Xu <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent fd7b4f9 commit 669b0cb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/proc/task_mmu.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2665,8 +2665,10 @@ static int pagemap_scan_get_args(struct pm_scan_arg *arg,
26652665
return -EFAULT;
26662666
if (!arg->vec && arg->vec_len)
26672667
return -EINVAL;
2668+
if (UINT_MAX == SIZE_MAX && arg->vec_len > SIZE_MAX)
2669+
return -EINVAL;
26682670
if (arg->vec && !access_ok((void __user *)(long)arg->vec,
2669-
arg->vec_len * sizeof(struct page_region)))
2671+
size_mul(arg->vec_len, sizeof(struct page_region))))
26702672
return -EFAULT;
26712673

26722674
/* Fixup default values */

0 commit comments

Comments
 (0)