CVE-2026-99917: mm/swap: fix swap_cache_get_folio() returning a folio that left the swap cache
In the Linux kernel, the following vulnerability has been resolved:
mm/swap: fix swapcachegetfolio() returning a folio that left the swap cache
swapcachegetfolio() reads the folio from the swap table and takes a reference with foliotryget(), without any lock. If the folio is removed from the swap cache and freed in between, and its memory gets reused, foliotryget() still succeeds and we return a page that has nothing to do with the swap entry:
CPU 0 CPU 1 doswappage() swapcachegetfolio() swptb = swaptableget() folio = swptbtofolio(swptb) madvise(MADVDONTNEED) zapnonpresentptes() swapputentriesdirect() swapputentriescluster() trytoreclaimswap() swapcachedelfolio() folioput() <- freed page reused, e.g. as an anon folio of another task foliotryget(folio) <- succeeds return folio swapupdatereadahead() <- may clear PGreadahead on it foliolockorretry() <- locks it foliomatchesswapentry() fails, unlock and put
filemapgetentry() does the same lockless lookup for the page cache, and after foliotryget() it rechecks the xarray, because the folio may have been freed and reused in between. swapcachegetfolio() lost that recheck when the swap cache moved to the swap table.
So CPU 0 writes to a folio it doesn't own: it may clear PGreadahead and takes the folio lock of someone else's page, before foliomatchesswapentry() finds out the folio is not ours.
When the race occurs, a swap fault can acquire a reference to a physical page that has been freed and reused for an unrelated purpose, potentially by another process. The fault handler may then clear that page's PGreadahead/PGreclaim flag, wait on or acquire its folio lock, and potentially attempt to remove it from an unrelated swap cache.
These operations can interfere with unrelated workloads and may cause unexpected stalls and impaired reclaim. The subsequent swap-entry validation normally prevents the wrong folio from being mapped into the faulting process.
It's documented that caller always double checks the folio so this part is harmless from the aspect of data corruption or crash.
Recheck the slot after foliotryget() and retry if it no longer holds this folio.
[akpm@linux-foundation.org: add LLM-generated description of userspace impact]
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
In the Linux kernel’s swap_cache_get_folio(), recheck the swap-table slot after folio_try_get() and retry if it no longer holds the folio.