-
Notifications
You must be signed in to change notification settings - Fork 189
fix: avoid page_table_check BUG on time namespace VVAR page #1578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
smira
wants to merge
1
commit into
main
Choose a base branch
from
fix-page-table-check-timens-vvar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+81
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
kernel/build/patches/0006-mm-page_table_check-do-not-track-special-PFN-mapped-PTEs.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| From: Andrey Smirnov <andrey.smirnov@siderolabs.com> | ||
| Date: Mon, 8 Jun 2026 00:00:00 +0000 | ||
| Subject: [PATCH] mm/page_table_check: do not track special (PFN-mapped) PTEs | ||
|
|
||
| The vDSO data store ("[vvar]") special mapping is created as a VM_PFNMAP | ||
| mapping and its pages are installed into userspace with vmf_insert_pfn(), | ||
| which produces *special* PTEs (pte_special()). On x86 and arm64 (and | ||
| riscv) pte_user_accessible_page() only tests the PRESENT/USER bits and | ||
| does not exclude special PTEs, so page_table_check accounts these PFN | ||
| mappings in the per-page anon/file map counters even though they are not | ||
| rmap-managed pages (vm_normal_page() returns NULL for them). | ||
|
|
||
| Most of these data pages live in the kernel image and are never freed, so | ||
| the stray accounting is invisible. The time-namespace VVAR page is the | ||
| exception: it is a real alloc_page() page that is released with | ||
| __free_page() in free_time_ns() when the last task of a time namespace | ||
| exits. Across the map / unmap / vdso_join_timens() zap transitions the | ||
| special-PTE accounting is not balanced for this page, so a non-zero | ||
| file_map_count survives to the free path and trips: | ||
|
|
||
| kernel BUG at mm/page_table_check.c:143! | ||
| __page_table_check_zero+... | ||
| __free_frozen_pages+... | ||
| free_time_ns+... | ||
| free_nsproxy+... | ||
| do_exit / do_group_exit | ||
|
|
||
| This reproduces under heavy container/CI churn (rapid creation and | ||
| teardown of time namespaces via CLONE_NEWTIME, e.g. runc / docker-init / | ||
| tini) on x86_64 and arm64, and was independently reported by syzbot on | ||
| riscv. It only manifests when CONFIG_PAGE_TABLE_CHECK is active. | ||
|
|
||
| Special PTEs have no struct-page rmap semantics and must never have been | ||
| tracked by page table check. Skip them in both the set and clear paths so | ||
| the counters stay balanced (always zero) for PFN-mapped pages, regardless | ||
| of how the architecture defines pte_user_accessible_page(). pte_special() | ||
| is available generically (a no-op returning false on architectures | ||
| without ARCH_HAS_PTE_SPECIAL), so this is a single, arch-independent fix. | ||
|
|
||
| Mainline sidesteps this since commit 05988dba1179 ("vdso/datastore: | ||
| Allocate data pages dynamically", v7.0) switched the mapping to | ||
| VM_MIXEDMAP + vmf_insert_page() with balanced struct-page accounting, but | ||
| 6.18.y still uses the PFNMAP path and needs this fix. | ||
|
|
||
| Reported-by: syzbot+2b5fe617654be3d8848b@syzkaller.appspotmail.com | ||
| Link: https://github.com/siderolabs/talos/issues/13496 | ||
| Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com> | ||
| --- | ||
| mm/page_table_check.c | 12 ++++++++++-- | ||
| 1 file changed, 10 insertions(+), 2 deletions(-) | ||
|
|
||
| --- a/mm/page_table_check.c | ||
| +++ b/mm/page_table_check.c | ||
| @@ -150,7 +150,15 @@ | ||
| if (&init_mm == mm) | ||
| return; | ||
|
|
||
| - if (pte_user_accessible_page(pte)) { | ||
| + /* | ||
| + * PFN-mapped (special) PTEs - e.g. the vDSO/time-namespace "[vvar]" | ||
| + * mapping installed via vmf_insert_pfn() - are not rmap-managed and | ||
| + * must not be tracked here. Tracking them can leave a non-zero map | ||
| + * count on a struct page that is later freed (the time namespace VVAR | ||
| + * page in free_time_ns()), tripping the BUG_ON() in | ||
| + * __page_table_check_zero(). | ||
| + */ | ||
| + if (pte_user_accessible_page(pte) && !pte_special(pte)) { | ||
| page_table_check_clear(pte_pfn(pte), PAGE_SIZE >> PAGE_SHIFT); | ||
| } | ||
| } | ||
| @@ -205,7 +213,7 @@ | ||
|
|
||
| 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); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.