Skip to content

Commit faeec8e

Browse files
davidhildenbrandakpm00
authored andcommitted
mm/page_alloc: don't call pfn_to_page() on possibly non-existent PFN in split_large_buddy()
In split_large_buddy(), we might call pfn_to_page() on a PFN that might not exist. In corner cases, such as when freeing the highest pageblock in the last memory section, this could result with CONFIG_SPARSEMEM && !CONFIG_SPARSEMEM_EXTREME in __pfn_to_section() returning NULL and and __section_mem_map_addr() dereferencing that NULL pointer. Let's fix it, and avoid doing a pfn_to_page() call for the first iteration, where we already have the page. So far this was found by code inspection, but let's just CC stable as the fix is easy. Link: https://lkml.kernel.org/r/[email protected] Fixes: fd919a8 ("mm: page_isolation: prepare for hygienic freelists") Signed-off-by: David Hildenbrand <[email protected]> Reported-by: Vlastimil Babka <[email protected]> Closes: https://lkml.kernel.org/r/[email protected] Reviewed-by: Vlastimil Babka <[email protected]> Reviewed-by: Zi Yan <[email protected]> Acked-by: Johannes Weiner <[email protected]> Cc: Yu Zhao <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 8ac662f commit faeec8e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

mm/page_alloc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,13 +1238,15 @@ static void split_large_buddy(struct zone *zone, struct page *page,
12381238
if (order > pageblock_order)
12391239
order = pageblock_order;
12401240

1241-
while (pfn != end) {
1241+
do {
12421242
int mt = get_pfnblock_migratetype(page, pfn);
12431243

12441244
__free_one_page(page, pfn, zone, order, mt, fpi);
12451245
pfn += 1 << order;
1246+
if (pfn == end)
1247+
break;
12461248
page = pfn_to_page(pfn);
1247-
}
1249+
} while (1);
12481250
}
12491251

12501252
static void free_one_page(struct zone *zone, struct page *page,

0 commit comments

Comments
 (0)