Skip to content

Commit

Permalink
mm/page_alloc.c: avoid potential NULL pointer dereference
Browse files Browse the repository at this point in the history
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/[email protected]
Fixes: 6bb1545 ("mm, page_alloc: spread allocations across zones before introducing fragmentation")
Signed-off-by: Andrey Ryabinin <[email protected]>
Acked-by: Mel Gorman <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
aryabinin authored and torvalds committed Apr 26, 2019
1 parent ee8ab0e commit 8139ad0
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3432,6 +3432,9 @@ alloc_flags_nofragment(struct zone *zone, gfp_t gfp_mask)
alloc_flags |= ALLOC_KSWAPD;

#ifdef CONFIG_ZONE_DMA32
if (!zone)
return alloc_flags;

if (zone_idx(zone) != ZONE_NORMAL)
goto out;

Expand Down

0 comments on commit 8139ad0

Please sign in to comment.