CVE-2026-139799: mm/shmem: hold off eviction in shmem_writeout()

Published Nov 30, 2026
·
Updated

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

mm/shmem: hold off eviction in shmemwriteout()

Once shmemwriteout() 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 swapwriteout() was the last thing the function did. But since it puts the folio back when swapwriteout() returns AOPWRITEPAGEACTIVATE, it uses the mapping and the inode afterwards:

reclaim last close of an unlinked file shmemwriteout() shmemdeletefrompagecache() swapwriteout() zswapstore() fails shmemevictinode() writeback is disabled shmemtruncaterange() return AOPWRITEPAGEACTIVATE shmemfreeswap() destroyinode() ... RCU grace period, freed shmemaddtopagecache(mapping) xaslockirq() <- use after free

swapwriteout() 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.

shmemunuse() already added infrastructure to deal with that. Reuse info->stopeviction to protect the inode during writeout. Increment it before removing the folio from the page cache, and decrement it after swapwriteout() and any attempted reinsertion and inode accounting. In shmemevictinode(), 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 ]

Affected Software

1 affected component
Linux Linux kernel

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Compensating control

    In shmem_writeout(), use info->stop_eviction to protect the inode during writeout: increment the counter before removing the folio from the page cache, then decrement it after swap_writeout() and any attempted reinsertion and inode accounting. In shmem_evict_inode(), wait for the counter to reach zero.

Event History

Nov 30, 2026
CVE Published
via MITRE·01:38 PM
Data Sourced
via MITRE·01:38 PM
Description

Frequently Asked Questions

1

Which systems are exposed to the problematic writeout path?

The path is relevant when zswap is enabled and zswap cannot take the folio because memory.zswap.writeback is set to 0 for the folio's memory cgroup or one of its ancestors. The issue is triggered when swap_writeout() returns AOP_WRITEPAGE_ACTIVATE under those conditions.

2

What lifecycle event makes this a use-after-free risk?

After the folio is moved from the page cache to the swap cache, its lock no longer keeps the inode alive. Truncation and eviction can free the swap entry and destroy the inode while shmem_writeout() later uses the mapping and inode to add the folio back to the page cache.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203