linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Uladzislau Rezki <urezki@gmail.com>
To: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Linux Memory Management List <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Baoquan He <bhe@redhat.com>,
	 Christoph Hellwig <hch@infradead.org>
Subject: Re: [PATCH] lib/test_vmalloc.c: avoid garbage in page array
Date: Thu, 25 May 2023 22:04:11 +0200	[thread overview]
Message-ID: <CA+KHdyVSD=vHh-WQxS_PrJ8GnBQZGFPgcS5AkmkyoUxpe_ziEw@mail.gmail.com> (raw)
In-Reply-To: <20230524082424.10022-1-lstoakes@gmail.com>

On Wed, May 24, 2023 at 10:24 AM Lorenzo Stoakes <lstoakes@gmail.com> wrote:
>
> 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).
>
> Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
> ---
>  lib/test_vmalloc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c
> index 9dd9745d365f..3718d9886407 100644
> --- a/lib/test_vmalloc.c
> +++ b/lib/test_vmalloc.c
> @@ -369,7 +369,7 @@ vm_map_ram_test(void)
>         int i;
>
>         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)
>                 return -1;
>
> --
> 2.40.1
>
Uh.. :)

Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>

--
Uladzislau Rezki


  reply	other threads:[~2023-05-25 20:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-24  8:24 Lorenzo Stoakes
2023-05-25 20:04 ` Uladzislau Rezki [this message]
2023-05-26  0:08 ` Baoquan He
2023-05-26  7:13   ` Lorenzo Stoakes
2023-05-26  8:56     ` Baoquan He
2023-05-26  9:10       ` Lorenzo Stoakes
2023-05-27 10:11         ` Baoquan He
2023-05-27 22:04           ` Lorenzo Stoakes
2023-05-27 10:13 ` Baoquan He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+KHdyVSD=vHh-WQxS_PrJ8GnBQZGFPgcS5AkmkyoUxpe_ziEw@mail.gmail.com' \
    --to=urezki@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bhe@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox