CVE-2024-26960: mm: swap: fix race between free_swap_and_cache() and swapoff()
In the Linux kernel, the following vulnerability has been resolved:
mm: swap: fix race between free_swap_and_cache() and swapoff()
There was previously a theoretical window where swapoff() could run and
teardown a swap_info_struct while a call to free_swap_and_cache() was
running in another thread. This could cause, amongst other bad
possibilities, swap_page_trans_huge_swapped() (called by
free_swap_and_cache()) to access the freed memory for swap_map.
This is a theoretical problem and I haven't been able to provoke it from a
test case. But there has been agreement based on code review that this is
possible (see link below).
Fix it by using get_swap_device()/put_swap_device(), which will stall
swapoff(). There was an extra check in _swap_info_get() to confirm that
the swap entry was not free. This isn't present in get_swap_device()
because it doesn't make sense in general due to the race between getting
the reference and swapoff. So I've added an equivalent check directly in
free_swap_and_cache().
Details of how to provoke one possible issue (thanks to David Hildenbrand
for deriving this):
--8<-----
__swap_entry_free() might be the last user and result in
"count == SWAP_HAS_CACHE".
swapoff->try_to_unuse() will stop as soon as soon as si->inuse_pages==0.
So the question is: could someone reclaim the folio and turn
si->inuse_pages==0, before we completed swap_page_trans_huge_swapped().
Imagine the following: 2 MiB folio in the swapcache. Only 2 subpages are
still references by swap entries.
Process 1 still references subpage 0 via swap entry.
Process 2 still references subpage 1 via swap entry.
Process 1 quits. Calls free_swap_and_cache().
-> count == SWAP_HAS_CACHE
[then, preempted in the hypervisor etc.]
Process 2 quits. Calls free_swap_and_cache().
-> count == SWAP_HAS_CACHE
Process 2 goes ahead, passes swap_page_trans_huge_swapped(), and calls
__try_to_reclaim_swap().
__try_to_reclaim_swap()->folio_free_swap()->delete_from_swap_cache()->
put_swap_folio()->free_swap_slot()->swapcache_free_entries()->
swap_entry_free()->swap_range_free()->
...
WRITE_ONCE(si->inuse_pages, si->inuse_pages - nr_entries);
What stops swapoff to succeed after process 2 reclaimed the swap cache
but before process1 finished its call to swap_page_trans_huge_swapped()?
--8<-----
Security readout for executives and security teams
Plain-English summary
A race in Linux swap-memory handling could let one thread use memory after another disables swap and frees it. The source rates potential impact as high, including confidentiality, integrity, and availability, but triggering requires local access, elevated timing complexity, and specific concurrent activity. The Linux description calls the issue theoretical and reports no successful test reproduction.
Executive priority
Schedule remediation through normal high-severity kernel patching, with faster treatment for shared or untrusted multi-user Linux hosts. This is not presently an emergency exploitation event: available evidence describes a difficult, theoretical local race and does not establish exploitation. Avoid deferral solely because no reproducer exists, since the unsafe lifetime condition was accepted through code review.
Technical view
CVE-2024-26960 is a CWE-362 race between free_swap_and_cache() and swapoff(). swapoff() could destroy swap_info_struct while another thread accesses its freed swap_map through swap_page_trans_huge_swapped(), creating a possible use-after-free condition. The kernel fix holds a swap-device reference with get_swap_device()/put_swap_device() and adds an equivalent free-entry check.
Likely exposure
Exposure is limited to Linux systems running a listed affected kernel and exercising swap. The supplied record identifies versions including 4.11, 5.10.215, 5.15.154, 6.1.84, 6.6.24, 6.7.12, 6.8.3, and 6.9. Distribution backports may change actual status, so kernel version alone is insufficient.
Exploitation context
The CVSS vector is local, high-complexity, low-privilege, and requires no user interaction. Successful triggering appears to require precise concurrency between freeing swap-cache entries and swapoff. The record is not in KEV, provides no evidence of active exploitation, and states that the issue could not be reproduced in testing.
Researcher notes
The security consequence is described broadly rather than demonstrated; the supplied evidence does not establish a reliable trigger or specific post-race outcome. Exposure assessment should account for vendor backports and configuration. The seven stable-kernel commit references appear to represent fixes across maintained branches, but the bundle does not map each commit to a branch, so consult vendor metadata before declaring a system fixed.
Mitigation direction
Install a vendor-supported kernel containing the applicable stable fix or distribution backport.
Check Linux distribution or appliance-vendor advisories for the exact corrected package version.
Prioritize multi-user systems where untrusted local users can run processes and swap is enabled.
Use vendor-recommended mitigations if immediate kernel replacement is operationally impractical.
Validation and detection
Record the running kernel and installed kernel package versions on potentially exposed systems.
Confirm whether swap is configured or active, without treating disabled swap as proof of permanent remediation.
Compare package versions against vendor advisories and backport notices, not upstream version numbers alone.
Verify the applicable stable commit or equivalent patch is present in the deployed kernel source package.
After updating, reboot into the corrected kernel and confirm the running version.
Generated from the cited source records. This long-tail analysis has not been individually reviewed by a named human.
Potential ATT&CK relevance
Conservative CVE-to-ATT&CK context
These mappings and lookup hints may be relevant to the vulnerability behavior, CWE, affected product, or exposure path. Glexia-inferred context is not an official MITRE, ATT&CK, CWE, or CVE Program mapping.
ATT&CK lookup starting points
Use these exact CWE pages and searches to review the Glexia ATT&CK library from this CVE's weakness and description context.
cwe · low confidence lookup
CWE-362: Exact CWE lookup
Use the exact CWE identifier as the starting point before reviewing related ATT&CK behavior. Open the exact CWE lookup page first, then review the ATT&CK searches from that MITRE weakness context. This is a Glexia lookup hint, not an official ATT&CK mapping.
These fields come from the CVE record and ADP containers, not from Glexia's Take. They preserve time-varying source decisions such as CISA SSVC, KEV status, CVSS metrics, and provider references.
We collect every scored CVSS vector available in the official CNA and ADP containers. When more than one version is present, the table keeps the source vectors side by side instead of collapsing them into the highest score.
CWE links open Glexia weakness intelligence pages with official CWE context, developer remediation guidance, and related CVE mappings.
CWE-362 · source CWE mapping
Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition') represents a recurring weakness pattern that can create exploitable paths when design, validation, or implementation controls are missing.