The patch titled Subject: mm/khugepaged: fix invalid page access in release_pte_pages() has been added to the -mm mm-unstable branch. Its filename is mm-khugepaged-fix-invalid-page-access-in-release_pte_pages.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-khugepaged-fix-invalid-page-access-in-release_pte_pages.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm 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 via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: "Vishal Moola (Oracle)" <vishal.moola@xxxxxxxxx> Subject: mm/khugepaged: fix invalid page access in release_pte_pages() Date: Mon, 13 Feb 2023 13:43:24 -0800 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@xxxxxxxxxxx/ Link: https://lkml.kernel.org/r/20230213214324.34215-1-vishal.moola@xxxxxxxxx Signed-off-by: Vishal Moola (Oracle) <vishal.moola@xxxxxxxxx> Fixes: 9bdfeea46f49 ("mm/khugepaged: convert release_pte_pages() to use folios") Reported-by: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx> Debugged-by: Alexandre Ghiti <alex@xxxxxxxx> Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- --- a/mm/khugepaged.c~mm-khugepaged-fix-invalid-page-access-in-release_pte_pages +++ a/mm/khugepaged.c @@ -511,11 +511,17 @@ static void release_pte_pages(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) { _ Patches currently in -mm which might be from vishal.moola@xxxxxxxxx are mm-khugepaged-fix-invalid-page-access-in-release_pte_pages.patch mm-add-folio_estimated_sharers.patch mm-mempolicy-convert-queue_pages_pmd-to-queue_folios_pmd.patch mm-mempolicy-convert-queue_pages_pte_range-to-queue_folios_pte_range.patch mm-mempolicy-convert-queue_pages_hugetlb-to-queue_folios_hugetlb.patch mm-mempolicy-convert-queue_pages_required-to-queue_folio_required.patch mm-mempolicy-convert-migrate_page_add-to-migrate_folio_add.patch mm-add-folio_get_nontail_page.patch mm-migrate-add-folio_movable_ops.patch mm-migrate-convert-isolate_movable_page-to-use-folios.patch mm-migrate-convert-putback_movable_pages-to-use-folios.patch