All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/page_alloc: do bulk array bounds check after checking populated elements
@ 2021-06-18 12:51 Mel Gorman
  2021-06-28  4:27 ` Dave Jones
  0 siblings, 1 reply; 6+ messages in thread
From: Mel Gorman @ 2021-06-18 12:51 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Dan Carpenter, Jesper Dangaard Brouer, Vlastimil Babka, Linux-MM,
	LKML, Mel Gorman

Dan Carpenter reported the following

  The patch 0f87d9d30f21: "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.

Fixes: 0f87d9d30f21 ("mm/page_alloc: add an array-based interface to the bulk page allocator")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mel Gorman <mgorman@techsinguliarity.net>
---
 mm/page_alloc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 7124bb00219d..ef2265f86b91 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5056,6 +5056,10 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
 	while (page_array && nr_populated < nr_pages && page_array[nr_populated])
 		nr_populated++;
 
+	/* Already populated array? */
+	if (unlikely(page_array && nr_pages - nr_populated == 0))
+		return 0;
+
 	/* Use the single page allocator for one page. */
 	if (nr_pages - nr_populated == 1)
 		goto failed;

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-28 15:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 12:51 [PATCH] mm/page_alloc: do bulk array bounds check after checking populated elements Mel Gorman
2021-06-28  4:27 ` Dave Jones
2021-06-28  4:59   ` Dave Jones
2021-06-28 11:53   ` Mel Gorman
2021-06-28 14:48     ` Dave Jones
2021-06-28 15:03       ` Mel Gorman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.