Skip to contentSkip to conversation

hugetlbfs: don't access uninitialized memmaps in pfn_range_valid_gigantic()

PATCH Applied David Hildenbrand 3 participants 3 messages Oct 15, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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]

Fixes f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online") # visible after d0dc12e86b319
Cc [email protected] # v4.13+
Cc Anshuman Khandual <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
---
 mm/hugetlb.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/hugetlb.c +2 -3
index ef37c85423a5..b45a95363a84 100644
@@ -1084,11 +1084,10 @@ static bool pfn_range_valid_gigantic(struct zone *z,
 	struct page *page;
 
 	for (i = start_pfn; i < end_pfn; i++) {
-		if (!pfn_valid(i))
+		page = pfn_to_online_page(i);
+		if (!page)
 			return false;
 
-		page = pfn_to_page(i);
-
 		if (page_zone(page) != z)
 			return false;
 
Signature · 1 line
2.21.0
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · David Hildenbrand

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]

Quoted 8 lines
Fixes f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online") # visible after d0dc12e86b319
Cc [email protected] # v4.13+
Cc Anshuman Khandual <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>

Thanks!

Quoted 24 lines
---
 mm/hugetlb.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/hugetlb.c +2 -3
index ef37c85423a5..b45a95363a84 100644
@@ -1084,11 +1084,10 @@ static bool pfn_range_valid_gigantic(struct zone *z,
 	struct page *page;
 
 	for (i = start_pfn; i < end_pfn; i++) {
-		if (!pfn_valid(i))
+		page = pfn_to_online_page(i);
+		if (!page)
 			return false;
 
-		page = pfn_to_page(i);
-
 		if (page_zone(page) != z)
 			return false;
 
Signature · 1 line
2.21.0
Signature · 2 lines
Michal Hocko
SUSE Labs
Reviewed-by on v1 1/1
#2 lore raw
In reply to David Hildenbrand
Quoted 18 lines · David Hildenbrand

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]

Quoted 8 lines
Fixes f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online") # visible after d0dc12e86b319
Cc [email protected] # v4.13+
Cc Anshuman Khandual <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>

Thanks David,

Signature · 1 line
Mike Kravetz