x86: add boundary check for 32bit res before expand e820 resource to alignment

fix hang with HIGHMEM_64G and 32bit resource. According to hpa and
Linus, use (resource_size_t)-1 to fend off big ranges.

Analyzed by hpa

Reported-and-tested-by: Mikael Pettersson <mikpe@it.uu.se>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Yinghai Lu and committed by Linus Torvalds 7c5371c4 43644679

+10 -6
+10 -6
arch/x86/kernel/e820.c
··· 1383 1383 return 32*1024*1024; 1384 1384 } 1385 1385 1386 + #define MAX_RESOURCE_SIZE ((resource_size_t)-1) 1387 + 1386 1388 void __init e820_reserve_resources_late(void) 1387 1389 { 1388 1390 int i; ··· 1402 1400 * avoid stolen RAM: 1403 1401 */ 1404 1402 for (i = 0; i < e820.nr_map; i++) { 1405 - struct e820entry *entry = &e820_saved.map[i]; 1406 - resource_size_t start, end; 1403 + struct e820entry *entry = &e820.map[i]; 1404 + u64 start, end; 1407 1405 1408 1406 if (entry->type != E820_RAM) 1409 1407 continue; 1410 1408 start = entry->addr + entry->size; 1411 - end = round_up(start, ram_alignment(start)); 1412 - if (start == end) 1409 + end = round_up(start, ram_alignment(start)) - 1; 1410 + if (end > MAX_RESOURCE_SIZE) 1411 + end = MAX_RESOURCE_SIZE; 1412 + if (start >= end) 1413 1413 continue; 1414 - reserve_region_with_split(&iomem_resource, start, 1415 - end - 1, "RAM buffer"); 1414 + reserve_region_with_split(&iomem_resource, start, end, 1415 + "RAM buffer"); 1416 1416 } 1417 1417 } 1418 1418