Skip to content

Commit 23b1fe3

Browse files
Dan Carpentersmb49
authored andcommitted
fs/proc/task_mmu: prevent integer overflow in pagemap_scan_get_args()
BugLink: https://bugs.launchpad.net/bugs/2101042 commit 669b0cb81e4e4e78cff77a5b367c7f70c0c6c05e upstream. 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/39d41335-dd4d-48ed-8a7f-402c57d8ea84@stanley.mountain Fixes: 52526ca ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Cc: Andrei Vagin <avagin@google.com> Cc: Andrii Nakryiko <andrii@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: David Hildenbrand <david@redhat.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Michał Mirosław <mirq-linux@rere.qmqm.pl> Cc: Muhammad Usama Anjum <usama.anjum@collabora.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Peter Xu <peterx@redhat.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent 5483199 commit 23b1fe3

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
@@ -2369,8 +2369,10 @@ static int pagemap_scan_get_args(struct pm_scan_arg *arg,
23692369
return -EFAULT;
23702370
if (!arg->vec && arg->vec_len)
23712371
return -EINVAL;
2372+
if (UINT_MAX == SIZE_MAX && arg->vec_len > SIZE_MAX)
2373+
return -EINVAL;
23722374
if (arg->vec && !access_ok((void __user *)(long)arg->vec,
2373-
arg->vec_len * sizeof(struct page_region)))
2375+
size_mul(arg->vec_len, sizeof(struct page_region))))
23742376
return -EFAULT;
23752377

23762378
/* Fixup default values */

0 commit comments

Comments
 (0)