From 2ff8267436362532848b73b7beab7fd36015b0c5 Mon Sep 17 00:00:00 2001 From: Markus Gothe Date: Thu, 2 May 2024 15:36:36 +0200 Subject: [PATCH] page_alloc.c: Sanity check for NULL pointers. get_pageblock_bitmap() might in very rare cicumstances return NULL which must be handled accordingly or otherwise we will end up with a kernel crash. --- mm/page_alloc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 540af9a120e6..ab230e349862 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -486,6 +486,9 @@ static __always_inline unsigned long __get_pfnblock_flags_mask(struct page *page unsigned long word; bitmap = get_pageblock_bitmap(page, pfn); + if (unlikely(bitmap == NULL)) + return 0; + bitidx = pfn_to_bitidx(page, pfn); word_bitidx = bitidx / BITS_PER_LONG; bitidx &= (BITS_PER_LONG-1); @@ -528,6 +531,9 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags, BUILD_BUG_ON(MIGRATE_TYPES > (1 << PB_migratetype_bits)); bitmap = get_pageblock_bitmap(page, pfn); + if (unlikely(bitmap == NULL)) + return; + bitidx = pfn_to_bitidx(page, pfn); word_bitidx = bitidx / BITS_PER_LONG; bitidx &= (BITS_PER_LONG-1); -- 2.43.2