CVE-2024-26960: mm: swap: fix race between free_swap_and_cache() and swapoff()

Published May 1, 2024
·
Updated

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

mm: swap: fix race between freeswapandcache() and swapoff()

The Linux kernel CVE team has assigned CVE-2024-26960 to this issue.

Upstream advisory: https://lore.kernel.org/linux-cve-announce/2024050129-CVE-2024-26960-ad6b@gregkh/T

Other sources

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

mm: swap: fix race between freeswapandcache() and swapoff()

There was previously a theoretical window where swapoff() could run and teardown a swapinfostruct while a call to freeswapandcache() was running in another thread. This could cause, amongst other bad possibilities, swappagetranshugeswapped() (called by freeswapandcache()) to access the freed memory for swapmap.

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 getswapdevice()/putswapdevice(), which will stall swapoff(). There was an extra check in swapinfoget() to confirm that the swap entry was not free. This isn't present in getswapdevice() 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 freeswapandcache().

Details of how to provoke one possible issue (thanks to David Hildenbrand for deriving this):

--8<-----

swapentryfree() might be the last user and result in "count == SWAPHASCACHE".

swapoff->trytounuse() will stop as soon as soon as si->inusepages==0.

So the question is: could someone reclaim the folio and turn si->inusepages==0, before we completed swappagetranshugeswapped().

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 freeswapandcache(). -> count == SWAPHASCACHE [then, preempted in the hypervisor etc.]

Process 2 quits. Calls freeswapandcache(). -> count == SWAPHASCACHE

Process 2 goes ahead, passes swappagetranshugeswapped(), and calls trytoreclaimswap().

trytoreclaimswap()->foliofreeswap()->deletefromswapcache()-> putswapfolio()->freeswapslot()->swapcachefreeentries()-> swapentryfree()->swaprangefree()-> ... WRITEONCE(si->inusepages, si->inusepages - nrentries);

What stops swapoff to succeed after process 2 reclaimed the swap cache but before process1 finished its call to swappagetranshugeswapped()?

--8<-----

NVD

Affected Software

19 affected componentsFixes available
redhat/kernel<5.10.215
5.10.215
redhat/kernel<5.15.154
5.15.154
redhat/kernel<6.1.84
6.1.84
redhat/kernel<6.6.24
6.6.24
redhat/kernel<6.7.12
6.7.12
redhat/kernel<6.8.3
6.8.3
redhat/kernel<6.9
6.9
Linux Linux kernel>=4.11<5.10.215
Linux Linux kernel>=5.11<5.15.154
Linux Linux kernel>=5.16<6.1.84
Linux Linux kernel>=6.2<6.6.24
Linux Linux kernel>=6.7<6.7.12
Linux Linux kernel>=6.8<6.8.3
Debian Debian Linux=10.0
IBM Security Verify Governance<=ISVG 10.0.2
IBM Security Verify Governance, Identity Manager Software Stack<=ISVG 10.0.2
IBM Security Verify Governance, Identity Manager Virtual Appliance<=ISVG 10.0.2
IBM Security Verify Governance Identity Manager Container<=ISVG 10.0.2
debian/linux
5.10.223-15.10.234-16.1.129-16.1.135-16.12.27-1

Event History

May 1, 2024
CVE Published
via MITRE·05:19 AM
Data Sourced
via MITRE·05:19 AM
Description
Data Sourced
via NVD·06:15 AM
RemedyDescriptionSeverityWeaknessAffected Software
Data Sourced
via Red Hat·04:33 PM
DescriptionSeverityAffected Software
Jun 8, 2024
Data Sourced
via Launchpad·01:11 AM
Description
Apr 28, 2025
Data Sourced
via Ubuntu·02:23 PM
RemedyDescriptionSeverityAffected Software

Parent advisories

This vulnerability appears in the following advisories.

Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2024-26960?

CVE-2024-26960 has been assessed with a medium severity rating.

2

How do I fix CVE-2024-26960?

To mitigate CVE-2024-26960, update the Linux kernel to one of the fixed versions listed in the advisory.

3

Which Linux kernel versions are affected by CVE-2024-26960?

CVE-2024-26960 affects several Linux kernel versions including 5.10, 5.15, 6.1, and others prior to their respective fixed releases.

4

Can CVE-2024-26960 be exploited remotely?

CVE-2024-26960 requires specific conditions and may not be easily exploitable remotely.

5

Is there a workaround for CVE-2024-26960?

There are no known effective workarounds for CVE-2024-26960; updating to a patched kernel is recommended.

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