CVE-2024-26759: mm/swap: fix race when skipping swapcache

Published Apr 3, 2024
·
Updated

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

mm/swap: fix race when skipping swapcache

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

Upstream advisory: https://lore.kernel.org/linux-cve-announce/2024040304-CVE-2024-26759-45f1@gregkh/T

Other sources

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

mm/swap: fix race when skipping swapcache

When skipping swapcache for SWPSYNCHRONOUSIO, if two or more threads swapin the same entry at the same time, they get different pages (A, B). Before one thread (T0) finishes the swapin and installs page (A) to the PTE, another thread (T1) could finish swapin of page (B), swapfree the entry, then swap out the possibly modified page reusing the same entry. It breaks the ptesame check in (T0) because PTE value is unchanged, causing ABA problem. Thread (T0) will install a stalled page (A) into the PTE and cause data corruption.

One possible callstack is like this:

CPU0 CPU1 ---- ---- doswappage() doswappage() with same entry swapreadfolio() <- read to page A swapreadfolio() <- read to page B ... setpteat() swapfree() <- entry is free ptesame() <- Check pass, PTE seems unchanged, but page A is stalled! swapfree() <- page B content lost! setpteat() <- staled page A installed!

And besides, for ZRAM, swapfree() allows the swap device to discard the entry content, so even if page (B) is not modified, if swapreadfolio() on CPU0 happens later than swapfree() on CPU1, it may also cause data loss.

To fix this, reuse swapcacheprepare which will pin the swap entry using the cache flag, and allow only one thread to swap it in, also prevent any parallel code from putting the entry in the cache. Release the pin after PT unlocked.

Racers just loop and wait since it's a rare and very short event. A scheduletimeoutuninterruptible(1) call is added to avoid repeated page faults wasting too much CPU, causing livelock or adding too much noise to perf statistics. A similar livelock issue was described in commit 029c4628b2eb ("mm: swap: get rid of livelock in swapin readahead")

Reproducer:

This race issue can be triggered easily using a well constructed reproducer and patched brd (with a delay in read path) [1]:

With latest 6.8 mainline, race caused data loss can be observed easily: $ gcc -g -lpthread test-thread-swap-race.c && ./a.out Polulating 32MB of memory region... Keep swapping out... Starting round 0... Spawning 65536 workers... 32746 workers spawned, wait for done... Round 0: Error on 0x5aa00, expected 32746, got 32743, 3 data loss! Round 0: Error on 0x395200, expected 32746, got 32743, 3 data loss! Round 0: Error on 0x3fd000, expected 32746, got 32737, 9 data loss! Round 0 Failed, 15 data loss!

This reproducer spawns multiple threads sharing the same memory region using a small swap device. Every two threads updates mapped pages one by one in opposite direction trying to create a race, with one dedicated thread keep swapping out the data out using madvise.

The reproducer created a reproduce rate of about once every 5 minutes, so the race should be totally possible in production.

After this patch, I ran the reproducer for over a few hundred rounds and no data loss observed.

Performance overhead is minimal, microbenchmark swapin 10G from 32G zram:

Before: 10934698 us After: 11157121 us Cached: 13155355 us (Dropping SWPSYNCHRONOUSIO flag)

[kasong@tencent.com: v4] Link:

IBM

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

mm/swap: fix race when skipping swapcache

When skipping swapcache for SWPSYNCHRONOUSIO, if two or more threads swapin the same entry at the same time, they get different pages (A, B). Before one thread (T0) finishes the swapin and installs page (A) to the PTE, another thread (T1) could finish swapin of page (B), swapfree the entry, then swap out the possibly modified page reusing the same entry. It breaks the ptesame check in (T0) because PTE value is unchanged, causing ABA problem. Thread (T0) will install a stalled page (A) into the PTE and cause data corruption.

One possible callstack is like this:

CPU0 CPU1 ---- ---- doswappage() doswappage() with same entry <direct swapin path> <direct swapin path> <alloc page A> <alloc page B> swapreadfolio() <- read to page A swapreadfolio() <- read to page B <slow on later locks or interrupt> <finished swapin first> ... setpteat() swapfree() <- entry is free <write to page B, now page A stalled> <swap out page B to same swap entry> ptesame() <- Check pass, PTE seems unchanged, but page A is stalled! swapfree() <- page B content lost! setpteat() <- staled page A installed!

And besides, for ZRAM, swapfree() allows the swap device to discard the entry content, so even if page (B) is not modified, if swapreadfolio() on CPU0 happens later than swapfree() on CPU1, it may also cause data loss.

To fix this, reuse swapcacheprepare which will pin the swap entry using the cache flag, and allow only one thread to swap it in, also prevent any parallel code from putting the entry in the cache. Release the pin after PT unlocked.

Racers just loop and wait since it's a rare and very short event. A scheduletimeoutuninterruptible(1) call is added to avoid repeated page faults wasting too much CPU, causing livelock or adding too much noise to perf statistics. A similar livelock issue was described in commit 029c4628b2eb ("mm: swap: get rid of livelock in swapin readahead")

Reproducer:

This race issue can be triggered easily using a well constructed reproducer and patched brd (with a delay in read path) [1]:

With latest 6.8 mainline, race caused data loss can be observed easily: $ gcc -g -lpthread test-thread-swap-race.c && ./a.out Polulating 32MB of memory region... Keep swapping out... Starting round 0... Spawning 65536 workers... 32746 workers spawned, wait for done... Round 0: Error on 0x5aa00, expected 32746, got 32743, 3 data loss! Round 0: Error on 0x395200, expected 32746, got 32743, 3 data loss! Round 0: Error on 0x3fd000, expected 32746, got 32737, 9 data loss! Round 0 Failed, 15 data loss!

This reproducer spawns multiple threads sharing the same memory region using a small swap device. Every two threads updates mapped pages one by one in opposite direction trying to create a race, with one dedicated thread keep swapping out the data out using madvise.

The reproducer created a reproduce rate of about once every 5 minutes, so the race should be totally possible in production.

After this patch, I ran the reproducer for over a few hundred rounds and no data loss observed.

Performance overhead is minimal, microbenchmark swapin 10G from 32G zram:

Before: 10934698 us After: 11157121 us Cached: 13155355 us (Dropping SWPSYNCHRONOUSIO flag)

[kasong@tencent.com: v4]

NVD

Affected Software

17 affected componentsFixes available
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
Linux Linux kernel>=4.15<6.1.80
Linux Linux kernel>=6.2<6.6.19
Linux Linux kernel>=6.7<6.7.7
Linux Linux kernel=6.8-rc1
Linux Linux kernel=6.8-rc2
Linux Linux kernel=6.8-rc3
Linux Linux kernel=6.8-rc4
Linux Linux kernel=6.8-rc5
redhat/kernel<6.1.80
6.1.80
redhat/kernel<6.6.19
6.6.19
redhat/kernel<6.7.7
6.7.7
redhat/kernel<6.8
6.8
Microsoft cbl2 kernel 5.15.186.1-1

Event History

Apr 3, 2024
CVE Published
via MITRE·05:00 PM
Data Sourced
via MITRE·05:00 PM
Description
Apr 4, 2024
Data Sourced
via Red Hat·12:14 AM
DescriptionSeverityAffected Software
Sep 4, 2025
Data Sourced
via Microsoft·12:41 AM
DescriptionSeverityWeakness
Data Sourced
via Microsoft·12:41 AM
Affected Software
Updated
via Microsoft·12:41 AM
DescriptionSeverity

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-26759?

The severity of CVE-2024-26759 is classified as medium.

2

How do I fix CVE-2024-26759?

To fix CVE-2024-26759, upgrade the Linux kernel to version 6.1.80, 6.6.19, 6.7.7, or 6.8.

3

What versions of the Linux kernel are affected by CVE-2024-26759?

CVE-2024-26759 affects Linux kernel versions prior to 6.1.80, 6.6.19, 6.7.7, and 6.8.

4

Is CVE-2024-26759 exploitable remotely?

CVE-2024-26759 does not have a known remote exploit vector.

5

What components of the Linux kernel are impacted by CVE-2024-26759?

CVE-2024-26759 impacts the memory management and swap functionalities within the Linux kernel.

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