CVE-2026-139799

mm/shmem: hold off eviction in shmem_writeout()

Published Nov 30, 2026 CVSS 3.1 · 7 High EPSS n/a KEV · Not listed
Description
In the Linux kernel, the following vulnerability has been resolved:

mm/shmem: hold off eviction in shmem_writeout()

Once shmem_writeout() has moved the folio from the page cache to the
swap cache, the folio lock no longer keeps the inode alive: truncation
and eviction find a swap entry, free it and do not wait for anybody.
That did not matter as long as swap_writeout() was the last thing the
function did. But since it puts the folio back when swap_writeout()
returns AOP_WRITEPAGE_ACTIVATE, it uses the mapping and the inode
afterwards:

reclaim last close of an unlinked file
shmem_writeout()
shmem_delete_from_page_cache()
swap_writeout()
zswap_store() fails shmem_evict_inode()
writeback is disabled shmem_truncate_range()
return AOP_WRITEPAGE_ACTIVATE shmem_free_swap()
destroy_inode()
... RCU grace period, freed
shmem_add_to_page_cache(mapping)
xas_lock_irq() <- use after free

swap_writeout() behaves that way if zswap is enabled, cannot take the
folio and the memcg or one of its ancestors has memory.zswap.writeback
set to 0.

shmem_unuse() already added infrastructure to deal with that.
Reuse info->stop_eviction to protect the inode during writeout. Increment
it before removing the folio from the page cache, and decrement it after
swap_writeout() and any attempted reinsertion and inode accounting.
In shmem_evict_inode(), wait for the counter to reach zero even if
swapoff has already removed the inode from the swap list. Add some helpers
to make the code easier to digest.

There is a known remaining issue with two swapoffs racing, and the empty
list check not being able to detect that race. That will be addressed
separately later.

Fix generated by an LLM and sent by Josef Bacik in private.

[ david: code cleanups; improve description ]

Analysis

AI-generated

Technical impact

The Linux kernel’s shmem_writeout() routine can release an inode from the page cache while still holding a reference to its folio. If zswap is enabled and swap_writeout() re‑activates the folio, the code may access the mapping and inode after they have been freed, creating a use‑after‑free error (CWE-416). A related race condition (CWE-362) can also occur if zswap writeback is disabled for a memory cgroup, allowing the same freed references to be used again. The result is kernel memory corruption, crashes, or a potential privilege escalation if an attacker can trigger the write‑out path.

Affected Systems

All Linux kernel builds that contain the unpatched mm/shmem implementation before the commit in the patch series are potentially affected. The advisory does not specify a version range, so any kernel where the shmem_writeout()/shmem_unuse logic remains unchanged is vulnerable.

Risk and Exploitability

No CVSS score is available for this entry, but the flaw operates in the core kernel memory manager and can lead to a severe state of unrecoverable failure. EPSS information is not available and the vulnerability is not listed in the CISA KEV catalog. It is inferred that exploitation would likely require local privileged access to trigger the writeout path and that a mitigation in the form of disabling zswap or setting memory.zswap.writeback to 1 can reduce the race. The lack of an EPSS score and current lack of public exploits suggest a moderate to high risk depending on the exposure of the affected kernel.

Remediation

No solution or workaround provided in the CVE record.

OpenCVE Recommended Actions

  • Apply the kernel patch that implements the shmem_writeout() fix from the commit referenced in the advisory.
  • Upgrade to a Linux kernel release that includes this patch if the patch cannot be applied directly.
  • As a temporary measure, disable zswap or ensure memory.zswap.writeback is enabled for all memory cgroups to avoid the race condition that triggers the use‑after‑free.

Generated by OpenCVE AI on December 1, 2026 at 03:19 UTC.

Tracking

Sign in to view the affected projects.

Advisories

No advisories available
History
Type Values Removed Values Added
Metrics cvssV3_1

{'score': 7, 'vector': 'CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H'}

Type Values Removed Values Added
Weaknesses CWE-362
CWE-416
Type Values Removed Values Added
Description In the Linux kernel, the following vulnerability has been resolved: mm/shmem: hold off eviction in shmem_writeout() Once shmem_writeout() has moved the folio from the page cache to the swap cache, the folio lock no longer keeps the inode alive: truncation and eviction find a swap entry, free it and do not wait for anybody. That did not matter as long as swap_writeout() was the last thing the function did. But since it puts the folio back when swap_writeout() returns AOP_WRITEPAGE_ACTIVATE, it uses the mapping and the inode afterwards: reclaim last close of an unlinked file shmem_writeout() shmem_delete_from_page_cache() swap_writeout() zswap_store() fails shmem_evict_inode() writeback is disabled shmem_truncate_range() return AOP_WRITEPAGE_ACTIVATE shmem_free_swap() destroy_inode() ... RCU grace period, freed shmem_add_to_page_cache(mapping) xas_lock_irq() <- use after free swap_writeout() behaves that way if zswap is enabled, cannot take the folio and the memcg or one of its ancestors has memory.zswap.writeback set to 0. shmem_unuse() already added infrastructure to deal with that. Reuse info->stop_eviction to protect the inode during writeout. Increment it before removing the folio from the page cache, and decrement it after swap_writeout() and any attempted reinsertion and inode accounting. In shmem_evict_inode(), wait for the counter to reach zero even if swapoff has already removed the inode from the swap list. Add some helpers to make the code easier to digest. There is a known remaining issue with two swapoffs racing, and the empty list check not being able to detect that race. That will be addressed separately later. Fix generated by an LLM and sent by Josef Bacik in private. [ david: code cleanups; improve description ]
Title mm/shmem: hold off eviction in shmem_writeout()
First Time appeared Linux
Linux linux Kernel
CPEs cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
Vendors & Products Linux
Linux linux Kernel
References
Weaknesses
  • CWE-362

    Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')

  • CWE-416

    Use After Free

Sources

Status
PUBLISHED
Assigner
Linux
Published
Updated
Dec 1, 2026, 5:43 AM
Reserved
Nov 30, 2026, 1:22 PM
Status
Received
Published
Nov 30, 2026, 2:20 PM
Modified
Dec 1, 2026, 6:17 AM