Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c5371c4 authored by Yinghai Lu's avatar Yinghai Lu Committed by Linus Torvalds
Browse files

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: default avatarMikael Pettersson <mikpe@it.uu.se>
Signed-off-by: default avatarYinghai Lu <yinghai@kernel.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 43644679
Loading
Loading
Loading
Loading
+10 −6
Original line number Original line Diff line number Diff line
@@ -1383,6 +1383,8 @@ static unsigned long ram_alignment(resource_size_t pos)
	return 32*1024*1024;
	return 32*1024*1024;
}
}


#define MAX_RESOURCE_SIZE ((resource_size_t)-1)

void __init e820_reserve_resources_late(void)
void __init e820_reserve_resources_late(void)
{
{
	int i;
	int i;
@@ -1400,17 +1402,19 @@ void __init e820_reserve_resources_late(void)
	 * avoid stolen RAM:
	 * avoid stolen RAM:
	 */
	 */
	for (i = 0; i < e820.nr_map; i++) {
	for (i = 0; i < e820.nr_map; i++) {
		struct e820entry *entry = &e820_saved.map[i];
		struct e820entry *entry = &e820.map[i];
		resource_size_t start, end;
		u64 start, end;


		if (entry->type != E820_RAM)
		if (entry->type != E820_RAM)
			continue;
			continue;
		start = entry->addr + entry->size;
		start = entry->addr + entry->size;
		end = round_up(start, ram_alignment(start));
		end = round_up(start, ram_alignment(start)) - 1;
		if (start == end)
		if (end > MAX_RESOURCE_SIZE)
			end = MAX_RESOURCE_SIZE;
		if (start >= end)
			continue;
			continue;
		reserve_region_with_split(&iomem_resource, start,
		reserve_region_with_split(&iomem_resource, start, end,
						  end - 1, "RAM buffer");
					  "RAM buffer");
	}
	}
}
}