Skip to content

Commit b3b64eb

Browse files
gormanmtorvalds
authored andcommitted
mm/page_alloc: do bulk array bounds check after checking populated elements
Dan Carpenter reported the following The patch 0f87d9d: "mm/page_alloc: add an array-based interface to the bulk page allocator" from Apr 29, 2021, leads to the following static checker warning: mm/page_alloc.c:5338 __alloc_pages_bulk() warn: potentially one past the end of array 'page_array[nr_populated]' The problem can occur if an array is passed in that is fully populated. That potentially ends up allocating a single page and storing it past the end of the array. This patch returns 0 if the array is fully populated. Link: https://lkml.kernel.org/r/20210618125102.GU30378@techsingularity.net Fixes: 0f87d9d ("mm/page_alloc: add an array-based interface to the bulk page allocator") Signed-off-by: Mel Gorman <mgorman@techsinguliarity.net> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Cc: Jesper Dangaard Brouer <brouer@redhat.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b08e50d commit b3b64eb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mm/page_alloc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5056,6 +5056,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
50565056
while (page_array && nr_populated < nr_pages && page_array[nr_populated])
50575057
nr_populated++;
50585058

5059+
/* Already populated array? */
5060+
if (unlikely(page_array && nr_pages - nr_populated == 0))
5061+
return 0;
5062+
50595063
/* Use the single page allocator for one page. */
50605064
if (nr_pages - nr_populated == 1)
50615065
goto failed;

0 commit comments

Comments
 (0)