# CVE-2025-38242: mm: userfaultfd: fix race of userfaultfd\_move and swap cache

> Archived entry. Full-text search covers entries since 2026-11-10; exact IDs work for all years.

- **Severity:** HIGH 7.8
- **CVSS:** 7.8 (v3.1, CNA) `CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`
- **CVSS metrics:** Attack vector: Local; Attack complexity: Low; Privileges required: Low; User interaction: None; Scope: Unchanged; Confidentiality impact: High; Integrity impact: High; Availability impact: High
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Not remotely exploitable (local or adjacent access needed)
- **EPSS:** 0.21% (percentile 6, 2026-11-26)
- **CWE:** CWE-362
- **Published:** 2025-07-09T10:42:25.396Z
- **Modified:** 2026-08-05T12:00:38.652Z

## Who should check

- Anyone running Linux \>= adef440691bab824e39c1b17382322d195e1fab0, \< 4c443046d8c9ed8724a4f4c3c2457d3ac8814b2f; \>= adef440691bab824e39c1b17382322d195e1fab0, \< db2ca8074955ca64187a4fb596dd290b9c446cd3; \>= adef440691bab824e39c1b17382322d195e1fab0, \< 0ea148a799198518d8ebab63ddd0bb6114a103bc
- Anyone running Linux 6.8

## Description

In the Linux kernel, the following vulnerability has been resolved:

mm: userfaultfd: fix race of userfaultfd\_move and swap cache

This commit fixes two kinds of races, they may have different results:

Barry reported a BUG\_ON in commit c50f8e6053b0, we may see the same
BUG\_ON if the filemap lookup returned NULL and folio is added to swap
cache after that.

If another kind of race is triggered (folio changed after lookup) we
may see RSS counter is corrupted:

\[  406.893936\] BUG: Bad rss-counter state mm:ffff0000c5a9ddc0
type:MM\_ANONPAGES val:-1
\[  406.894071\] BUG: Bad rss-counter state mm:ffff0000c5a9ddc0
type:MM\_SHMEMPAGES val:1

Because the folio is being accounted to the wrong VMA.

I'm not sure if there will be any data corruption though, seems no. 
The issues above are critical already.


On seeing a swap entry PTE, userfaultfd\_move does a lockless swap cache
lookup, and tries to move the found folio to the faulting vma.  Currently,
it relies on checking the PTE value to ensure that the moved folio still
belongs to the src swap entry and that no new folio has been added to the
swap cache, which turns out to be unreliable.

While working and reviewing the swap table series with Barry, following
existing races are observed and reproduced \[1\]:

In the example below, move\_pages\_pte is moving src\_pte to dst\_pte, where
src\_pte is a swap entry PTE holding swap entry S1, and S1 is not in the
swap cache:

CPU1                               CPU2
userfaultfd\_move
  move\_pages\_pte()
    entry = pte\_to\_swp\_entry(orig\_src\_pte);
    // Here it got entry = S1
    ... \< interrupted\> ...
                                   \<swapin src\_pte, alloc and use folio A\>
                                   // folio A is a new allocated folio
                                   // and get installed into src\_pte
                                   \<frees swap entry S1\>
                                   // src\_pte now points to folio A, S1
                                   // has swap count == 0, it can be freed
                                   // by folio\_swap\_swap or swap
                                   // allocator's reclaim.
                                   \<try to swap out another folio B\>
                                   // folio B is a folio in another VMA.
                                   \<put folio B to swap cache using S1 \>
                                   // S1 is freed, folio B can use it
                                   // for swap out with no problem.
                                   ...
    folio = filemap\_get\_folio(S1)
    // Got folio B here !!!
    ... \< interrupted again\> ...
                                   \<swapin folio B and free S1\>
                                   // Now S1 is free to be used again.
                                   \<swapout src\_pte & folio A using S1\>
                                   // Now src\_pte is a swap entry PTE
                                   // holding S1 again.
    folio\_trylock(folio)
    move\_swap\_pte
      double\_pt\_lock
      is\_pte\_pages\_stable
      // Check passed because src\_pte == S1
      folio\_move\_anon\_rmap(...)
      // Moved invalid folio B here !!!

The race window is very short and requires multiple collisions of multiple
rare events, so it's very unlikely to happen, but with a deliberately
constructed reproducer and increased time window, it can be reproduced
easily.

This can be fixed by checking if the folio returned by filemap is the
valid swap cache folio after acquiring the folio lock.

Another similar race is possible: filemap\_get\_folio may return NULL, but
folio (A) could be swapped in and then swapped out again using the same
swap entry after the lookup.  In such a case, folio (A) may remain in the
swap cache, so it must be moved too:

CPU1                               CPU2
userfaultfd\_move
  move\_pages\_pte()
    entry = pte\_to\_swp\_entry(orig\_src\_pte);
    // Here it got entry = S1, and S1 is not in swap cache
    folio = filemap\_get
---truncated---

## Affected and fixed versions

- Linux: \>= adef440691bab824e39c1b17382322d195e1fab0, \< 4c443046d8c9ed8724a4f4c3c2457d3ac8814b2f; \>= adef440691bab824e39c1b17382322d195e1fab0, \< db2ca8074955ca64187a4fb596dd290b9c446cd3; \>= adef440691bab824e39c1b17382322d195e1fab0, \< 0ea148a799198518d8ebab63ddd0bb6114a103bc (cvelist)
- Linux: 6.8 (cvelist)

## Mitigation

- Upgrade Linux to 0ea148a799198518d8ebab63ddd0bb6114a103bc or later.

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by CVE-2025-38242. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2025-38242.md
Affected: Linux >= adef440691bab824e39c1b17382322d195e1fab0, < 4c443046d8c9ed8724a4f4c3c2457d3ac8814b2f; >= adef440691bab824e39c1b17382322d195e1fab0, < db2ca8074955ca64187a4fb596dd290b9c446cd3; >= adef440691bab824e39c1b17382322d195e1fab0, < 0ea148a799198518d8ebab63ddd0bb6114a103bc; Linux 6.8
Fixed in: Linux 4c443046d8c9ed8724a4f4c3c2457d3ac8814b2f, Linux 0ea148a799198518d8ebab63ddd0bb6114a103bc

Steps:
1. Search this machine and project for Linux: dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is CVE-2025-38242 being exploited?

There is no confirmed exploitation: CVE-2025-38242 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known. EPSS estimates a 0.21% chance of exploitation in the next 30 days (as of 2026-11-26).

### How serious is CVE-2025-38242?

High: CVSS 7.8 (v3.1, scored by CNA). Not remotely exploitable (local or adjacent access needed).

### Which versions are affected by CVE-2025-38242?

Linux \>= adef440691bab824e39c1b17382322d195e1fab0, \< 4c443046d8c9ed8724a4f4c3c2457d3ac8814b2f; \>= adef440691bab824e39c1b17382322d195e1fab0, \< db2ca8074955ca64187a4fb596dd290b9c446cd3; \>= adef440691bab824e39c1b17382322d195e1fab0, \< 0ea148a799198518d8ebab63ddd0bb6114a103bc; Linux 6.8.

### Is there a fix for CVE-2025-38242?

Yes. Fixed in Linux 4c443046d8c9ed8724a4f4c3c2457d3ac8814b2f, Linux 0ea148a799198518d8ebab63ddd0bb6114a103bc. Upgrade Linux to 0ea148a799198518d8ebab63ddd0bb6114a103bc or later.

### How do I check if I'm affected by CVE-2025-38242?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- patch: <https://git.kernel.org/stable/c/4c443046d8c9ed8724a4f4c3c2457d3ac8814b2f>
- patch: <https://git.kernel.org/stable/c/db2ca8074955ca64187a4fb596dd290b9c446cd3>
- patch: <https://git.kernel.org/stable/c/0ea148a799198518d8ebab63ddd0bb6114a103bc>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- NVD: This product uses data from the NVD API but is not endorsed or certified by the NVD. <https://nvd.nist.gov/vuln/detail/CVE-2025-38242>

HTML: <https://flawdb.com/CVE-2025-38242> · JSON: <https://flawdb.com/api/v1/entries/CVE-2025-38242>
