# CVE-2026-23161: mm/shmem, swap: fix race of truncate and swap entry split

- Severity: High 7.3 (CVSS:3.1, scored by Linux) `CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:H/A:H`
- Known to be exploited: not in CISA's catalogue, which lists only what CISA has confirmed
- Likelihood of exploitation in the next 30 days (EPSS): 0.15%, higher than 2% of CVEs (2026-11-30)
- Published: 2026-02-14T16:01:26.569Z
- Modified: 2026-08-05T12:20:23.871Z
- Weaknesses: CWE-362
- Assigned by: Linux

## Description

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 xa_cmpxchg_irq to erase the swap entry, but it
gets the entry order before that using xa_get_order without lock
protection, and it may get an outdated order value if the entry is split
or changed in other ways after the xa_get_order and before the
xa_cmpxchg_irq.

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
xa_cmpxchg_irq 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,
find_lock_entries 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.

(As written by CVE List.)

## Affected

- Linux Linux: from 809bc86517cc408b5b8cb8e08e69096639432bc8 before a99f9a4669a04662c8f9efe0e62cafc598153139; from 809bc86517cc408b5b8cb8e08e69096639432bc8 before b23bee8cdb7aabce5701a7f57414db5a354ae8ed; from 809bc86517cc408b5b8cb8e08e69096639432bc8 before 8a1968bd997f45a9b11aefeabdd1232e1b6c7184; 6.12 (not affected: before 6.12; from 6.12.69 up to 6.12.*; from 6.18.9 up to 6.18.*; from 6.19 up to *)
- linux linux_kernel: from 6.12 before 6.12.69; from 6.13 before 6.18.9; 6.19

## Every score

- Linux: CVSS:3.1 7.3 High `CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:H/A:H`
- NVD: CVSS:3.1 4.7 Medium `CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:N/A:H`

## References

- <https://git.kernel.org/stable/c/a99f9a4669a04662c8f9efe0e62cafc598153139> (patch)
- <https://git.kernel.org/stable/c/b23bee8cdb7aabce5701a7f57414db5a354ae8ed> (patch)
- <https://git.kernel.org/stable/c/8a1968bd997f45a9b11aefeabdd1232e1b6c7184> (patch)

## Sources

- CVE List: [CVE-2026-23161](https://www.cve.org/CVERecord?id=CVE-2026-23161), CVE Terms of Use, modified 2026-08-05
- NVD: [CVE-2026-23161](https://nvd.nist.gov/vuln/detail/CVE-2026-23161), Public domain, modified 2026-06-17

---

Page: https://cve.day/CVE-2026-23161 · Whole record: https://cve.day/CVE-2026-23161.json · Rebuilt by cve.day 2026-11-25T22:59:13.896Z
