CVE-2026-99665: mm/khugepaged: preserve dirty bits when collapsing PTE-mapped THPs
In the Linux kernel, the following vulnerability has been resolved:
mm/khugepaged: preserve dirty bits when collapsing PTE-mapped THPs
trycollapseptemappedthp() clears PTEs without transferring their dirty bits to the folio. A shmem read fault can map a clean folio writable, so a later store only dirties the PTE. Losing that dirty bit allows reclaim to discard modified data.
The assumption that regular files are read-only is also obsolete since commit 1b6444331bebb ("mm/khugepaged: enable clean pagecache folio collapse for writable files"). In any case, transferring PTE dirty bits to the folio when removing mappings (and while the folio is still mapped) is the right thing to do.
Use getandclearptes() to collect the dirty bits and mark the folio dirty before unmapping it. Update the comment.
This was reproduced with shmem using MADVCOLLAPSE followed by MADVPAGEOUT.
Fix generated by an LLM and sent by Chris Mason in private.
[ david: adjust comment; simplify description; cover file-thp as well ]
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 6.18.64 - Upgrade
Upgrade
linux/Kernelto a version that resolves this vulnerability.Fixed in 7.3.5
Frequently Asked Questions
What workloads are exposed to possible data loss?
Workloads using shmem or writable file-backed mappings with PTE-mapped transparent huge pages may be exposed. The issue occurs when khugepaged collapses mappings whose modifications are represented only by PTE dirty bits.
What conditions are needed to trigger the issue?
A writable mapping must have data dirtied through a PTE while the underlying folio remains clean, followed by collapse of the PTE-mapped THP. The reported reproduction uses shmem with MADV_COLLAPSE followed by MADV_PAGEOUT.
What is the impact if the vulnerable collapse occurs?
The collapse can discard PTE dirty-bit state without marking the folio dirty. Reclaim may then treat modified data as clean and discard it.
How does the fix prevent the issue?
The fix collects dirty bits from PTEs being removed and marks the folio dirty before unmapping it. This preserves modification state through the collapse operation.