From: David Hildenbrand <david@redhat.com>
To: "Vishal Moola (Oracle)" <vishal.moola@gmail.com>,
akpm@linux-foundation.org
Cc: willy@infradead.org, m.szyprowski@samsung.com, alex@ghiti.fr,
linux-mm@kvack.org
Subject: Re: [PATCH] mm/khugepaged: Fix invalid page access in release_pte_pages()
Date: Tue, 14 Feb 2023 13:06:37 +0100 [thread overview]
Message-ID: <ba0e540d-7ae8-fb7c-d126-b3a8774335a9@redhat.com> (raw)
In-Reply-To: <20230213214324.34215-1-vishal.moola@gmail.com>
On 13.02.23 22:43, Vishal Moola (Oracle) wrote:
> release_pte_pages() converts from a pfn to a folio by using pfn_folio().
> If the pte is not mapped, pfn_folio() will result in undefined behavior
> which ends up causing a kernel panic[1].
>
> Only call pfn_folio() once we have validated that the pte is both valid
> and mapped to fix the issue.
>
> [1] https://lore.kernel.org/linux-mm/ff300770-afe9-908d-23ed-d23e0796e899@samsung.com/
>
> Fixes: 9bdfeea46f49 ("mm/khugepaged: convert release_pte_pages() to use folios")
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Debugged-by: Alexandre Ghiti <alex@ghiti.fr>
> Cc: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
> ---
> mm/khugepaged.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index b39ab219d5b7..bd54b957f69a 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -511,11 +511,17 @@ static void release_pte_pages(pte_t *pte, pte_t *_pte,
>
> while (--_pte >= pte) {
> pte_t pteval = *_pte;
> + unsigned long pfn;
>
> - folio = pfn_folio(pte_pfn(pteval));
> - if (!pte_none(pteval) && !is_zero_pfn(pte_pfn(pteval)) &&
> - !folio_test_large(folio))
> - release_pte_folio(folio);
> + if (pte_none(pteval))
> + continue;
> + pfn = pte_pfn(pteval);
> + if (is_zero_pfn(pfn))
> + continue;
> + folio = pfn_folio(pfn);
> + if (folio_test_large(folio))
> + continue;
> + release_pte_folio(folio);
> }
>
> list_for_each_entry_safe(folio, tmp, compound_pagelist, lru) {
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2023-02-14 12:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20230213214446eucas1p2630d6c5cb27183f546c2d9561d99b00a@eucas1p2.samsung.com>
2023-02-13 21:43 ` Vishal Moola (Oracle)
2023-02-13 22:56 ` Marek Szyprowski
2023-02-14 8:04 ` Alexandre Ghiti
2023-02-14 12:06 ` David Hildenbrand [this message]
2023-02-14 17:25 ` Yang Shi
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=ba0e540d-7ae8-fb7c-d126-b3a8774335a9@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=linux-mm@kvack.org \
--cc=m.szyprowski@samsung.com \
--cc=vishal.moola@gmail.com \
--cc=willy@infradead.org \
/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