# CVE-2026-31398: mm/rmap: fix incorrect pte restoration for lazyfree folios

> 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.18% (percentile 5, 2026-11-26)
- **CWE:** CWE-617
- **Published:** 2026-04-03T15:16:02.334Z
- **Modified:** 2026-08-05T12:22:08.041Z

## Who should check

- Anyone running Linux \>= 354dffd29575cdf13154e8fb787322354aa9efc4, \< 99888a4f340ca8e839a0524556bd4db76d63f4e0; \>= 354dffd29575cdf13154e8fb787322354aa9efc4, \< a0911ccdba41b0871abbf8412857bafedec3dbe1; \>= 354dffd29575cdf13154e8fb787322354aa9efc4, \< 29f40594a28114b9a9bc87f6cf7bbee9609628f2
- Anyone running Linux 6.15

## Description

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

mm/rmap: fix incorrect pte restoration for lazyfree folios

We batch unmap anonymous lazyfree folios by folio\_unmap\_pte\_batch.  If the
batch has a mix of writable and non-writable bits, we may end up setting
the entire batch writable.  Fix this by respecting writable bit during
batching.

Although on a successful unmap of a lazyfree folio, the soft-dirty bit is
lost, preserve it on pte restoration by respecting the bit during
batching, to make the fix consistent w.r.t both writable bit and
soft-dirty bit.

I was able to write the below reproducer and crash the kernel. 
Explanation of reproducer (set 64K mTHP to always):

Fault in a 64K large folio.  Split the VMA at mid-point with
MADV\_DONTFORK.  fork() - parent points to the folio with 8 writable ptes
and 8 non-writable ptes.  Merge the VMAs with MADV\_DOFORK so that
folio\_unmap\_pte\_batch() can determine all the 16 ptes as a batch.  Do
MADV\_FREE on the range to mark the folio as lazyfree.  Write to the memory
to dirty the pte, eventually rmap will dirty the folio.  Then trigger
reclaim, we will hit the pte restoration path, and the kernel will crash
with the trace given below.

The BUG happens at:

	BUG\_ON(atomic\_inc\_return(&ptc-\>anon\_map\_count) \> 1 && rw);

The code path is asking for anonymous page to be mapped writable into the
pagetable.  The BUG\_ON() firing implies that such a writable page has been
mapped into the pagetables of more than one process, which breaks
anonymous memory/CoW semantics.

\[   21.134473\] kernel BUG at mm/page\_table\_check.c:118!
\[   21.134497\] Internal error: Oops - BUG: 00000000f2000800 \[\#1\]  SMP
\[   21.135917\] Modules linked in:
\[   21.136085\] CPU: 1 UID: 0 PID: 1735 Comm: dup-lazyfree Not tainted 7.0.0-rc1-00116-g018018a17770 \#1028 PREEMPT
\[   21.136858\] Hardware name: linux,dummy-virt (DT)
\[   21.137019\] pstate: 21400005 (nzCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
\[   21.137308\] pc : page\_table\_check\_set+0x28c/0x2a8
\[   21.137607\] lr : page\_table\_check\_set+0x134/0x2a8
\[   21.137885\] sp : ffff80008a3b3340
\[   21.138124\] x29: ffff80008a3b3340 x28: fffffdffc3d14400 x27: ffffd1a55e03d000
\[   21.138623\] x26: 0040000000000040 x25: ffffd1a55f7dd000 x24: 0000000000000001
\[   21.139045\] x23: 0000000000000001 x22: 0000000000000001 x21: ffffd1a55f217f30
\[   21.139629\] x20: 0000000000134521 x19: 0000000000134519 x18: 005c43e000040000
\[   21.140027\] x17: 0001400000000000 x16: 0001700000000000 x15: 000000000000ffff
\[   21.140578\] x14: 000000000000000c x13: 005c006000000000 x12: 0000000000000020
\[   21.140828\] x11: 0000000000000000 x10: 005c000000000000 x9 : ffffd1a55c079ee0
\[   21.141077\] x8 : 0000000000000001 x7 : 005c03e000040000 x6 : 000000004000ffff
\[   21.141490\] x5 : ffff00017fffce00 x4 : 0000000000000001 x3 : 0000000000000002
\[   21.141741\] x2 : 0000000000134510 x1 : 0000000000000000 x0 : ffff0000c08228c0
\[   21.141991\] Call trace:
\[   21.142093\]  page\_table\_check\_set+0x28c/0x2a8 (P)
\[   21.142265\]  \_\_page\_table\_check\_ptes\_set+0x144/0x1e8
\[   21.142441\]  \_\_set\_ptes\_anysz.constprop.0+0x160/0x1a8
\[   21.142766\]  contpte\_set\_ptes+0xe8/0x140
\[   21.142907\]  try\_to\_unmap\_one+0x10c4/0x10d0
\[   21.143177\]  rmap\_walk\_anon+0x100/0x250
\[   21.143315\]  try\_to\_unmap+0xa0/0xc8
\[   21.143441\]  shrink\_folio\_list+0x59c/0x18a8
\[   21.143759\]  shrink\_lruvec+0x664/0xbf0
\[   21.144043\]  shrink\_node+0x218/0x878
\[   21.144285\]  \_\_node\_reclaim.constprop.0+0x98/0x338
\[   21.144763\]  user\_proactive\_reclaim+0x2a4/0x340
\[   21.145056\]  reclaim\_store+0x3c/0x60
\[   21.145216\]  dev\_attr\_store+0x20/0x40
\[   21.145585\]  sysfs\_kf\_write+0x84/0xa8
\[   21.145835\]  kernfs\_fop\_write\_iter+0x130/0x1c8
\[   21.145994\]  vfs\_write+0x2b8/0x368
\[   21.146119\]  ksys\_write+0x70/0x110
\[   21.146240\]  \_\_arm64\_sys\_write+0x24/0x38
\[   21.146380\]  invoke\_syscall+0x50/0x120
\[   21.146513\]  el0\_svc\_common.constprop.0+0x48/0xf8
\[   21.146679\]  do\_el0\_svc+0x28/0x40
\[   21.146798\]  el0\_svc+0x34/0x110
\[   21.146926\]  el0t
---truncated---

## Affected and fixed versions

- Linux: \>= 354dffd29575cdf13154e8fb787322354aa9efc4, \< 99888a4f340ca8e839a0524556bd4db76d63f4e0; \>= 354dffd29575cdf13154e8fb787322354aa9efc4, \< a0911ccdba41b0871abbf8412857bafedec3dbe1; \>= 354dffd29575cdf13154e8fb787322354aa9efc4, \< 29f40594a28114b9a9bc87f6cf7bbee9609628f2 (cvelist)
- Linux: 6.15 (cvelist)

## Mitigation

- Upgrade Linux to 29f40594a28114b9a9bc87f6cf7bbee9609628f2 or later.

## Check your systems with an agent

Paste this into a coding agent:

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

Details: https://flawdb.com/CVE-2026-31398.md
Affected: Linux >= 354dffd29575cdf13154e8fb787322354aa9efc4, < 99888a4f340ca8e839a0524556bd4db76d63f4e0; >= 354dffd29575cdf13154e8fb787322354aa9efc4, < a0911ccdba41b0871abbf8412857bafedec3dbe1; >= 354dffd29575cdf13154e8fb787322354aa9efc4, < 29f40594a28114b9a9bc87f6cf7bbee9609628f2; Linux 6.15
Fixed in: Linux 99888a4f340ca8e839a0524556bd4db76d63f4e0, Linux 29f40594a28114b9a9bc87f6cf7bbee9609628f2

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-2026-31398 being exploited?

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

### How serious is CVE-2026-31398?

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

### Which versions are affected by CVE-2026-31398?

Linux \>= 354dffd29575cdf13154e8fb787322354aa9efc4, \< 99888a4f340ca8e839a0524556bd4db76d63f4e0; \>= 354dffd29575cdf13154e8fb787322354aa9efc4, \< a0911ccdba41b0871abbf8412857bafedec3dbe1; \>= 354dffd29575cdf13154e8fb787322354aa9efc4, \< 29f40594a28114b9a9bc87f6cf7bbee9609628f2; Linux 6.15.

### Is there a fix for CVE-2026-31398?

Yes. Fixed in Linux 99888a4f340ca8e839a0524556bd4db76d63f4e0, Linux 29f40594a28114b9a9bc87f6cf7bbee9609628f2. Upgrade Linux to 29f40594a28114b9a9bc87f6cf7bbee9609628f2 or later.

### How do I check if I'm affected by CVE-2026-31398?

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/99888a4f340ca8e839a0524556bd4db76d63f4e0>
- patch: <https://git.kernel.org/stable/c/a0911ccdba41b0871abbf8412857bafedec3dbe1>
- patch: <https://git.kernel.org/stable/c/29f40594a28114b9a9bc87f6cf7bbee9609628f2>

## 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-2026-31398>

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