Vulnerability · Published Jul 9, 2025 · Assigned by Linux

CVE-2025-38242mm: userfaultfd: fix race of userfaultfd_move and swap cache

High 7.8

In plain English

A high-severity security flaw in Linux from Linux. There are no confirmed reports of exploitation so far. The chance it is exploited in the next 30 days is estimated at 0.1% (higher than 3% of all known vulnerabilities). Fixed versions are available - upgrade the affected package.

Severity (CVSS 3.1)7.8High
Exploit odds (30 days)0.1%top 97.1% of all CVEs
Exploited in the wildNo reportsnot in CISA KEV
Attack toolingNoneno public tooling known

Official 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 packages & fixed versions

EcosystemPackageFixed inAdvisory
Debian:13linux6.12.37-1DEBIAN-CVE-2025-38242
Debian:14linux6.12.37-1DEBIAN-CVE-2025-38242
Ubuntu:24.04:LTSlinuxno fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-allwinner-5.19no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-awsno fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-aws-5.19no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-aws-6.146.14.0-1015.15~24.04.1UBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-aws-6.2no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-aws-6.5no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-aws-6.8no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-azureno fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-azure-5.19no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-azure-6.11no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-azure-6.146.14.0-1014.14~24.04.1UBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-azure-6.2no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-azure-6.5no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-azure-6.8no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-azure-fdeno fix listedUBUNTU-CVE-2025-38242
Ubuntu:25.10linux-azure-fdeno fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-azure-fde-5.19no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-azure-fde-6.17no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-azure-fde-6.2no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-azure-fde-6.8no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-azure-nvidiano fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-azure-nvidia-6.146.14.0-1007.7UBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-gcpno fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-gcp-5.19no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-gcp-6.11no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-gcp-6.146.14.0-1018.19~24.04.1UBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-gcp-6.2no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-gcp-6.5no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-gcp-6.8no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-gkeno fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-gkeopno fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-hwe-5.19no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-hwe-6.11no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-hwe-6.2no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-hwe-6.5no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-hwe-6.8no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-ibmno fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-ibm-6.8no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-intelno fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-intel-iot-realtimeno fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-lowlatencyno fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-lowlatency-hwe-5.19no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-lowlatency-hwe-6.11no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-lowlatency-hwe-6.2no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-lowlatency-hwe-6.5no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-lowlatency-hwe-6.8no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-nvidiano fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-nvidia-6.11no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-nvidia-6.2no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-nvidia-6.5no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-nvidia-6.8no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-nvidia-lowlatencyno fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-nvidia-tegra6.8.0-1035.38USN-8781-1
Ubuntu:24.04:LTSlinux-nvidia-tegra6.8.0-1035.38UBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-oem-5.17no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-oem-6.0no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-oem-6.1no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-oem-6.11no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-oem-6.146.14.0-1014.14UBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-oem-6.5no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-oem-6.8no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-oracleno fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-oracle-6.146.14.0-1015.15~24.04.1UBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-oracle-6.5no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-oracle-6.8no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-raspino fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-raspi-realtimeno fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-realtimeno fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-realtimeno fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-riscvno fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-riscvno fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-riscv-5.19no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-riscv-6.146.14.0-34.34.1~24.04.1UBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-riscv-6.5no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-riscv-6.8no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-starfive-5.19no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-starfive-6.2no fix listedUBUNTU-CVE-2025-38242
Ubuntu:22.04:LTSlinux-starfive-6.5no fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-vmwareno fix listedUBUNTU-CVE-2025-38242
Ubuntu:24.04:LTSlinux-xilinxno fix listedUBUNTU-CVE-2025-38242

Affected products (as reported)

VendorProductVersions
Linux Linux adef440691bab824e39c1b17382322d195e1fab0 – before 4c443046d8c9ed8724a4f4c3c2457d3ac8814b2fadef440691bab824e39c1b17382322d195e1fab0 – before db2ca8074955ca64187a4fb596dd290b9c446cd3adef440691bab824e39c1b17382322d195e1fab0 – before 0ea148a799198518d8ebab63ddd0bb6114a103bc
Linux Linux 6.8

References