From: Dan Carpenter Date: Tue, 30 Oct 2018 22:04:32 +0000 (-0700) Subject: mm/gup_benchmark.c: prevent integer overflow in ioctl X-Git-Tag: v5.15~7679^2~87 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4b408c74ee5a0b74fc9265c2fe39b0e7dec7c056;p=platform%2Fkernel%2Flinux-starfive.git mm/gup_benchmark.c: prevent integer overflow in ioctl The concern here is that "gup->size" is a u64 and "nr_pages" is unsigned long. On 32 bit systems we could trick the kernel into allocating fewer pages than expected. Link: http://lkml.kernel.org/r/20181025061546.hnhkv33diogf2uis@kili.mountain Fixes: 64c349f4ae78 ("mm: add infrastructure for get_user_pages_fast() benchmarking") Signed-off-by: Dan Carpenter Acked-by: Kirill A. Shutemov Reviewed-by: Andrew Morton Cc: Stephen Rothwell Cc: Keith Busch Cc: "Michael S. Tsirkin" Cc: Kees Cook Cc: YueHaibing Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c index debf113..5b42d3d 100644 --- a/mm/gup_benchmark.c +++ b/mm/gup_benchmark.c @@ -27,6 +27,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd, int nr; struct page **pages; + if (gup->size > ULONG_MAX) + return -EINVAL; + nr_pages = gup->size / PAGE_SIZE; pages = kvcalloc(nr_pages, sizeof(void *), GFP_KERNEL); if (!pages)