The patch titled Subject: mm/page_alloc: do bulk array bounds check after checking populated elements has been added to the -mm tree. Its filename is mm-page_alloc-do-bulk-array-bounds-check-after-checking-populated-elements.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/mm-page_alloc-do-bulk-array-bounds-check-after-checking-populated-elements.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/mm-page_alloc-do-bulk-array-bounds-check-after-checking-populated-elements.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx> Subject: mm/page_alloc: do bulk array bounds check after checking populated elements 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. Link: https://lkml.kernel.org/r/20210618125102.GU30378@xxxxxxxxxxxxxxxxxxx Fixes: 0f87d9d30f21 ("mm/page_alloc: add an array-based interface to the bulk page allocator") Signed-off-by: Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxxx> Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx> Cc: Jesper Dangaard Brouer <brouer@xxxxxxxxxx> Cc: Vlastimil Babka <vbabka@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/page_alloc.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/mm/page_alloc.c~mm-page_alloc-do-bulk-array-bounds-check-after-checking-populated-elements +++ a/mm/page_alloc.c @@ -5056,6 +5056,10 @@ unsigned long __alloc_pages_bulk(gfp_t g 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; _ Patches currently in -mm which might be from mgorman@xxxxxxxxxxxxxxxxxxx are mm-page_alloc-do-bulk-array-bounds-check-after-checking-populated-elements.patch mm-page_alloc-split-per-cpu-page-lists-and-zone-stats.patch mm-page_alloc-split-per-cpu-page-lists-and-zone-stats-fix.patch mm-page_alloc-split-per-cpu-page-lists-and-zone-stats-fix-fix.patch mm-page_alloc-convert-per-cpu-list-protection-to-local_lock.patch mm-page_alloc-convert-per-cpu-list-protection-to-local_lock-fix.patch mm-vmstat-convert-numa-statistics-to-basic-numa-counters.patch mm-vmstat-inline-numa-event-counter-updates.patch mm-page_alloc-batch-the-accounting-updates-in-the-bulk-allocator.patch mm-page_alloc-reduce-duration-that-irqs-are-disabled-for-vm-counters.patch mm-page_alloc-explicitly-acquire-the-zone-lock-in-__free_pages_ok.patch mm-page_alloc-avoid-conflating-irqs-disabled-with-zone-lock.patch mm-page_alloc-update-pgfree-outside-the-zone-lock-in-__free_pages_ok.patch mm-page_alloc-delete-vmpercpu_pagelist_fraction.patch mm-page_alloc-disassociate-the-pcp-high-from-pcp-batch.patch mm-page_alloc-disassociate-the-pcp-high-from-pcp-batch-fix-2.patch mm-page_alloc-adjust-pcp-high-after-cpu-hotplug-events.patch mm-page_alloc-scale-the-number-of-pages-that-are-batch-freed.patch mm-page_alloc-limit-the-number-of-pages-on-pcp-lists-when-reclaim-is-active.patch mm-page_alloc-introduce-vmpercpu_pagelist_high_fraction.patch mm-page_alloc-introduce-vmpercpu_pagelist_high_fraction-fix.patch mm-page_alloc-move-free_the_page.patch mm-page_alloc-allow-high-order-pages-to-be-stored-on-the-per-cpu-lists.patch mm-page_alloc-split-pcp-high-across-all-online-cpus-for-cpuless-nodes.patch mm-vmscan-remove-kerneldoc-like-comment-from-isolate_lru_pages.patch mm-vmalloc-include-header-for-prototype-of-set_iounmap_nonlazy.patch mm-page_alloc-make-should_fail_alloc_page-a-static-function-should_fail_alloc_page-static.patch mm-mapping_dirty_helpers-remove-double-note-in-kerneldoc.patch mm-memcontrolc-fix-kerneldoc-comment-for-mem_cgroup_calculate_protection.patch mm-memory_hotplug-fix-kerneldoc-comment-for-__try_online_node.patch mm-memory_hotplug-fix-kerneldoc-comment-for-__remove_memory.patch mm-zbud-add-kerneldoc-fields-for-zbud_pool.patch mm-z3fold-add-kerneldoc-fields-for-z3fold_pool.patch mm-swap-make-swap_address_space-an-inline-function.patch mm-mmap_lock-remove-dead-code-for-config_tracing-configurations.patch mm-page_alloc-move-prototype-for-find_suitable_fallback.patch mm-swap-make-node_data-an-inline-function-on-config_flatmem.patch