FAILED: patch "[PATCH] mm/page_table_check: skip special zero mappings" failed to apply to 6.18-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 8db4bab826ccc9ec10fa41736a48031cd338d392
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026081741-service-sandbank-1034@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 8db4bab826ccc9ec10fa41736a48031cd338d392 Mon Sep 17 00:00:00 2001
From: Zhiling Zou <[email protected]>
Date: Thu, 23 Jul 2026 00:48:13 +0800
Subject: [PATCH] mm/page_table_check: skip special zero mappings
page_table_check_set() and page_table_check_clear() account mappings based on PageAnon(). Shared zero-page PTEs and huge zero PMDs are special mappings, but page_table_check can still account them as file-backed pages.
An unprivileged process can populate enough zero mappings to overflow file_map_count and hit the existing BUG_ON(). The PTE path can do this with the shared zero page, and the PMD path can do the same with huge zero mappings.
Skip special zero mappings in the user page-table accounting paths. Keep the PTE-side pte_special() check, and identify huge zero PMDs from the mapped folio instead of pmd_special(). That covers architectures where pmd_special() is a no-op without adding huge_zero_pfn checks to the generic counter helpers.
mm/page_table_check.c +16 -4
@@ -151,18 +151,29 @@ void __page_table_check_pte_clear(struct mm_struct *mm, unsigned long addr,if (&init_mm == mm)return ; -if (pte_user_accessible_page (mm, addr, pte)) +if (pte_user_accessible_page (mm, addr, pte) && !pte_special (pte))page_table_check_clear (pte_pfn (pte),PAGE_SIZE >>PAGE_SHIFT ); }EXPORT_SYMBOL (__page_table_check_pte_clear); +static inline bool page_table_check_huge_zero_pmd (pmd_t pmd) +{ +unsigned long pfn =pmd_pfn (pmd); + +if (!pfn_valid (pfn)) +return false; + +return is_huge_zero_folio (page_folio (pfn_to_page (pfn))); +} +void __page_table_check_pmd_clear (struct mm_struct *mm,unsigned long addr,pmd_t pmd) {if (&init_mm == mm)return ; -if (pmd_user_accessible_page (mm, addr, pmd)) +if (pmd_user_accessible_page (mm, addr, pmd) && + !page_table_check_huge_zero_pmd (pmd))page_table_check_clear (pmd_pfn (pmd),PMD_SIZE >>PAGE_SHIFT ); }EXPORT_SYMBOL (__page_table_check_pmd_clear);
@@ -208,7 +219,7 @@ void __page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr,for (i =0 ; i < nr; i++)__page_table_check_pte_clear (mm, addr +PAGE_SIZE * i,ptep_get (ptep + i)); -if (pte_user_accessible_page (mm, addr, pte)) +if (pte_user_accessible_page (mm, addr, pte) && !pte_special (pte))page_table_check_set (pte_pfn (pte), nr,pte_write (pte)); }EXPORT_SYMBOL (__page_table_check_ptes_set);
@@ -238,7 +249,8 @@ void __page_table_check_pmds_set(struct mm_struct *mm, unsigned long addr,for (i =0 ; i < nr; i++)__page_table_check_pmd_clear (mm, addr +PMD_SIZE * i, *(pmdp + i)); -if (pmd_user_accessible_page (mm, addr, pmd)) +if (pmd_user_accessible_page (mm, addr, pmd) && + !page_table_check_huge_zero_pmd (pmd))page_table_check_set (pmd_pfn (pmd), stride * nr,pmd_write (pmd)); }EXPORT_SYMBOL (__page_table_check_pmds_set);
Sasha Levin
maintainerPATCH 1/1 mm/page_table_check: skip special zero mappings
From: Zhiling Zou <[email protected]>
[ Upstream commit 8db4bab826ccc9ec10fa41736a48031cd338d392 ]
page_table_check_set() and page_table_check_clear() account mappings based on PageAnon(). Shared zero-page PTEs and huge zero PMDs are special mappings, but page_table_check can still account them as file-backed pages.
An unprivileged process can populate enough zero mappings to overflow file_map_count and hit the existing BUG_ON(). The PTE path can do this with the shared zero page, and the PMD path can do the same with huge zero mappings.
Skip special zero mappings in the user page-table accounting paths. Keep the PTE-side pte_special() check, and identify huge zero PMDs from the mapped folio instead of pmd_special(). That covers architectures where pmd_special() is a no-op without adding huge_zero_pfn checks to the generic counter helpers.
--- mm/page_table_check.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
mm/page_table_check.c +16 -4
@@ -150,18 +150,29 @@ void __page_table_check_pte_clear(struct mm_struct *mm, pte_t pte)if (&init_mm == mm)return ; -if (pte_user_accessible_page (pte)) { +if (pte_user_accessible_page (pte) && !pte_special (pte)) {page_table_check_clear (pte_pfn (pte),PAGE_SIZE >>PAGE_SHIFT ); } }EXPORT_SYMBOL (__page_table_check_pte_clear); +static inline bool page_table_check_huge_zero_pmd (pmd_t pmd) +{ +unsigned long pfn =pmd_pfn (pmd); + +if (!pfn_valid (pfn)) +return false; + +return is_huge_zero_folio (page_folio (pfn_to_page (pfn))); +} +void __page_table_check_pmd_clear (struct mm_struct *mm,pmd_t pmd) {if (&init_mm == mm)return ; -if (pmd_user_accessible_page (pmd)) { +if (pmd_user_accessible_page (pmd) && + !page_table_check_huge_zero_pmd (pmd)) {page_table_check_clear (pmd_pfn (pmd),PMD_SIZE >>PAGE_SHIFT ); } }
@@ -205,7 +216,7 @@ void __page_table_check_ptes_set(struct mm_struct *mm, pte_t *ptep, pte_t pte,for (i =0 ; i < nr; i++)__page_table_check_pte_clear (mm,ptep_get (ptep + i)); -if (pte_user_accessible_page (pte)) +if (pte_user_accessible_page (pte) && !pte_special (pte))page_table_check_set (pte_pfn (pte), nr,pte_write (pte)); }EXPORT_SYMBOL (__page_table_check_ptes_set);
@@ -231,7 +242,8 @@ void __page_table_check_pmds_set(struct mm_struct *mm, pmd_t *pmdp, pmd_t pmd,for (i =0 ; i < nr; i++)__page_table_check_pmd_clear (mm, *(pmdp + i)); -if (pmd_user_accessible_page (pmd)) +if (pmd_user_accessible_page (pmd) && + !page_table_check_huge_zero_pmd (pmd))page_table_check_set (pmd_pfn (pmd), stride * nr,pmd_write (pmd)); }EXPORT_SYMBOL (__page_table_check_pmds_set);
Signature · 1 line
2.53.0