CVE-2026-23161: mm/shmem, swap: fix race of truncate and swap entry split
In the Linux kernel, the following vulnerability has been resolved:
mm/shmem, swap: fix race of truncate and swap entry split
The helper for shmem swap freeing is not handling the order of swap entries correctly. It uses xacmpxchgirq to erase the swap entry, but it gets the entry order before that using xagetorder without lock protection, and it may get an outdated order value if the entry is split or changed in other ways after the xagetorder and before the xacmpxchgirq.
And besides, the order could grow and be larger than expected, and cause truncation to erase data beyond the end border. For example, if the target entry and following entries are swapped in or freed, then a large folio was added in place and swapped out, using the same entry, the xacmpxchgirq will still succeed, it's very unlikely to happen though.
To fix that, open code the Xarray cmpxchg and put the order retrieval and value checking in the same critical section. Also, ensure the order won't exceed the end border, skip it if the entry goes across the border.
Skipping large swap entries crosses the end border is safe here. Shmem truncate iterates the range twice, in the first iteration, findlockentries already filtered such entries, and shmem will swapin the entries that cross the end border and partially truncate the folio (split the folio or at least zero part of it). So in the second loop here, if we see a swap entry that crosses the end order, it must at least have its content erased already.
I observed random swapoff hangs and kernel panics when stress testing ZSWAP with shmem. After applying this patch, all problems are gone.
Affected Software
Event History
Frequently Asked Questions
What is the severity of CVE-2026-23161?
The severity of CVE-2026-23161 has not been explicitly rated, but vulnerabilities in the Linux kernel typically carry significant risk due to their potential impact on system security.
How do I fix CVE-2026-23161?
To fix CVE-2026-23161, apply the updates or patches provided in the latest Linux kernel release that address this specific vulnerability.
What type of systems are affected by CVE-2026-23161?
CVE-2026-23161 affects systems running the Linux kernel, particularly those utilizing memory management features related to shmem and swap.
Can CVE-2026-23161 lead to data loss?
Yes, if exploited, CVE-2026-23161 could potentially lead to data loss or corruption due to improper handling of memory management operations.
Is there a workaround for CVE-2026-23161?
There is no widely recommended workaround for CVE-2026-23161; patching the kernel is the best course of action.