Skip to content

Commit f231fe4

Browse files
davidhildenbrandtorvalds
authored andcommitted
hugetlbfs: don't access uninitialized memmaps in pfn_range_valid_gigantic()
Uninitialized memmaps contain garbage and in the worst case trigger kernel BUGs, especially with CONFIG_PAGE_POISONING. They should not get touched. Let's make sure that we only consider online memory (managed by the buddy) that has initialized memmaps. ZONE_DEVICE is not applicable. page_zone() will call page_to_nid(), which will trigger VM_BUG_ON_PGFLAGS(PagePoisoned(page), page) with CONFIG_PAGE_POISONING and CONFIG_DEBUG_VM_PGFLAGS when called on uninitialized memmaps. This can be the case when an offline memory block (e.g., never onlined) is spanned by a zone. Note: As explained by Michal in [1], alloc_contig_range() will verify the range. So it boils down to the wrong access in this function. [1] http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Fixes: f1dd2cd ("mm, memory_hotplug: do not associate hotadded memory to zones until online") [visible after d0dc12e] Signed-off-by: David Hildenbrand <[email protected]> Reported-by: Michal Hocko <[email protected]> Acked-by: Michal Hocko <[email protected]> Reviewed-by: Mike Kravetz <[email protected]> Cc: Anshuman Khandual <[email protected]> Cc: <[email protected]> [4.13+] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent f3057ad commit f231fe4

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

mm/hugetlb.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,11 +1084,10 @@ static bool pfn_range_valid_gigantic(struct zone *z,
10841084
struct page *page;
10851085

10861086
for (i = start_pfn; i < end_pfn; i++) {
1087-
if (!pfn_valid(i))
1087+
page = pfn_to_online_page(i);
1088+
if (!page)
10881089
return false;
10891090

1090-
page = pfn_to_page(i);
1091-
10921091
if (page_zone(page) != z)
10931092
return false;
10941093

0 commit comments

Comments
 (0)