From 60eb3dfc44e15d89d33298c691d0f8292c3f677c Mon Sep 17 00:00:00 2001 From: Andrey Ryabinin Date: Thu, 25 Apr 2019 22:23:58 -0700 Subject: [PATCH 1660/2944] mm/page_alloc.c: avoid potential NULL pointer dereference to #28825456 commit 8139ad043d632c0e9e12d760068a7a8e91659aa1 upstream. ac.preferred_zoneref->zone passed to alloc_flags_nofragment() can be NULL. 'zone' pointer unconditionally derefernced in alloc_flags_nofragment(). Bail out on NULL zone to avoid potential crash. Currently we don't see any crashes only because alloc_flags_nofragment() has another bug which allows compiler to optimize away all accesses to 'zone'. Link: http://lkml.kernel.org/r/20190423120806.3503-1-aryabinin@virtuozzo.com Fixes: 6bb154504f8b ("mm, page_alloc: spread allocations across zones before introducing fragmentation") Signed-off-by: Andrey Ryabinin Acked-by: Mel Gorman Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Xu Yu Reviewed-by: Yang Shi --- mm/page_alloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 5293c4f..793f5ce 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3572,6 +3572,9 @@ static bool zone_allows_reclaim(struct zone *local_zone, struct zone *zone) alloc_flags |= ALLOC_KSWAPD; #ifdef CONFIG_ZONE_DMA32 + if (!zone) + return alloc_flags; + if (zone_idx(zone) != ZONE_NORMAL) goto out; -- 1.8.3.1