CVE-2026-99918: mm/madvise: atomically clear the young bit on THP MADV_COLD
In the Linux kernel, the following vulnerability has been resolved:
mm/madvise: atomically clear the young bit on THP MADVCOLD
As-is, madvisecoldorpageoutpterange() discards the hardware young bit by invalidating the PMD, doing pmdmkold() and subsequently writing to the pmd again. However, it does so in a racy manner, looking at a possibly-stale snapshot. It's entirely possible that a write elsewhere set the hardware D bit, which this logic now loses.
Fix it by using pmdptestandclearyoung(). This is an atomic modification of the PMD entry, and thus safe against any possible racing writes. As a (nice) side-effect, this elides one non-required TLB flush in pmdpinvalidate().
This bug can interact with the swapping system in complicated ways, leading to data loss. For instance, if a folio is marked lazyfree, but was later read from, and then MADVCOLD'd while racing a write to that same THP, dropping the dirty bit may lead to data loss as reclaim/MADVPAGEOUT drops the "clean" anon folio:
T0 T1 ================================================================ MADVFREE(thp) | folio marked lazyfree | read(thp) | PMD marked young by hardware | | MADVCOLD(thp) write(thp) | if (pmdyoung(pmd)) { PMD marked dirty by hardware | set(pmdp, pmdmkold(pmd)); MADVPAGEOUT/reclaim | dirty bit may or may not be | set | reclaim/pageout may drop | the folio |
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
In madvise_cold_or_pageout_pte_range(), atomically clear the THP PMD young bit using pmdp_test_and_clear_young().