From d7014f34d538477364c38426b6ad21269f800c89 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Tue, 6 Jul 2021 08:13:14 +0000 Subject: [PATCH] mm/vmalloc.c:__vmalloc_area_node(): avoid 32-bit overflow mainline inclusion from mainline-5.11-rc1 commit 34fe653716b0d340bc26dd4823d2dbe00c57f849 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I3ZBYD CVE: NA ------------------------------------------------- With a machine with 3 TB (more than 2 TB memory). If you use vmalloc to allocate > 2 TB memory, the array_size below will be overflowed. The array_size is an unsigned int and can only be used to allocate less than 2 TB memory. If you pass 2*1028*1028*1024*1024 = 2 * 2^40 in the argument of vmalloc. The array_size will become 2*2^31 = 2^32. The 2^32 cannot be store with a 32 bit integer. The fix is to change the type of array_size to unsigned long. [akpm@linux-foundation.org: rework for current mainline] Link: https://bugzilla.kernel.org/show_bug.cgi?id=210023 Reported-by: Cc: Matthew Wilcox Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds (cherry picked from commit 34fe653716b0d340bc26dd4823d2dbe00c57f849) Signed-off-by: Yue Zou Reviewed-by: chenwandun Signed-off-by: Zheng Zengkai --- mm/vmalloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 3e8809c18188..74268996104a 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2479,9 +2479,11 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, { const gfp_t nested_gfp = (gfp_mask & GFP_RECLAIM_MASK) | __GFP_ZERO; unsigned int nr_pages = get_vm_area_size(area) >> PAGE_SHIFT; - unsigned int array_size = nr_pages * sizeof(struct page *), i; + unsigned long array_size; + unsigned int i; struct page **pages; + array_size = (unsigned long)nr_pages * sizeof(struct page *); gfp_mask |= __GFP_NOWARN; if (!(gfp_mask & (GFP_DMA | GFP_DMA32))) gfp_mask |= __GFP_HIGHMEM; -- GitLab