Commit 9f6c6ad1 authored by Lorenzo Stoakes's avatar Lorenzo Stoakes Committed by Andrew Morton

lib/test_vmalloc.c: avoid garbage in page array

It turns out that alloc_pages_bulk_array() does not treat the page_array
parameter as an output parameter, but rather reads the array and skips any
entries that have already been allocated.

This is somewhat unexpected and breaks this test, as we allocate the pages
array uninitialised on the assumption it will be overwritten.

As a result, the test was referencing uninitialised data and causing the
PFN to not be valid and thus a WARN_ON() followed by a null pointer deref
and panic.

In addition, this is an array of pointers not of struct page objects, so we
need only allocate an array with elements of pointer size.

We solve both problems by simply using kcalloc() and referencing
sizeof(struct page *) rather than sizeof(struct page).

Link: https://lkml.kernel.org/r/20230524082424.10022-1-lstoakes@gmail.com
Fixes: 869cb29a ("lib/test_vmalloc.c: add vm_map_ram()/vm_unmap_ram() test case")
Signed-off-by: default avatarLorenzo Stoakes <lstoakes@gmail.com>
Reviewed-by: default avatarUladzislau Rezki (Sony) <urezki@gmail.com>
Reviewed-by: default avatarBaoquan He <bhe@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent fee5eaec
...@@ -369,7 +369,7 @@ vm_map_ram_test(void) ...@@ -369,7 +369,7 @@ vm_map_ram_test(void)
int i; int i;
map_nr_pages = nr_pages > 0 ? nr_pages:1; map_nr_pages = nr_pages > 0 ? nr_pages:1;
pages = kmalloc(map_nr_pages * sizeof(struct page), GFP_KERNEL); pages = kcalloc(map_nr_pages, sizeof(struct page *), GFP_KERNEL);
if (!pages) if (!pages)
return -1; return -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment