CVE-2023-53178

Source
https://nvd.nist.gov/vuln/detail/CVE-2023-53178
Import Source
https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2023-53178.json
JSON Data
https://api.osv.dev/v1/vulns/CVE-2023-53178
Downstream
Related
Published
2025-09-15T14:04:23Z
Modified
2025-10-15T06:26:32.958205Z
Summary
mm: fix zswap writeback race condition
Details

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

mm: fix zswap writeback race condition

The zswap writeback mechanism can cause a race condition resulting in memory corruption, where a swapped out page gets swapped in with data that was written to a different page.

The race unfolds like this: 1. a page with data A and swap offset X is stored in zswap 2. page A is removed off the LRU by zpool driver for writeback in zswap-shrink work, data for A is mapped by zpool driver 3. user space program faults and invalidates page entry A, offset X is considered free 4. kswapd stores page B at offset X in zswap (zswap could also be full, if so, page B would then be IOed to X, then skip step 5.) 5. entry A is replaced by B in tree->rbroot, this doesn't affect the local reference held by zswap-shrink work 6. zswap-shrink work writes back A at X, and frees zswap entry A 7. swapin of slot X brings A in memory instead of B

The fix: Once the swap page cache has been allocated (case ZSWAPSWAPCACHENEW), zswap-shrink work just checks that the local zswap_entry reference is still the same as the one in the tree. If it's not the same it means that it's either been invalidated or replaced, in both cases the writeback is aborted because the local entry contains stale data.

Reproducer: I originally found this by running stress overnight to validate my work on the zswap writeback mechanism, it manifested after hours on my test machine. The key to make it happen is having zswap writebacks, so whatever setup pumps /sys/kernel/debug/zswap/writtenbackpages should do the trick.

In order to reproduce this faster on a vm, I setup a system with ~100M of available memory and a 500M swap file, then running stress --vm 1 --vm-bytes 300000000 --vm-stride 4000 makes it happen in matter of tens of minutes. One can speed things up even more by swinging /sys/module/zswap/parameters/maxpoolpercent up and down between, say, 20 and 1; this makes it reproduce in tens of seconds. It's crucial to set --vm-stride to something other than 4096 otherwise stress won't realize that memory has been corrupted because all pages would have the same data.

References

Affected packages

Git / git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git

Affected ranges

Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
2b2811178e85553405b86e3fe78357b9b95889ce
Fixed
2cab13f500a6333bd2b853783ac76be9e4956f8a
Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
2b2811178e85553405b86e3fe78357b9b95889ce
Fixed
ba700ea13bf0105a4773c654f7d3bef8adb64ab2
Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
2b2811178e85553405b86e3fe78357b9b95889ce
Fixed
04fc7816089c5a32c29a04ec94b998e219dfb946

Affected versions

v3.*

v3.11
v3.11-rc1
v3.11-rc2
v3.11-rc3
v3.11-rc4
v3.11-rc5
v3.11-rc6
v3.11-rc7
v3.12
v3.12-rc1
v3.12-rc2
v3.12-rc3
v3.12-rc4
v3.12-rc5
v3.12-rc6
v3.12-rc7
v3.13
v3.13-rc1
v3.13-rc2
v3.13-rc3
v3.13-rc4
v3.13-rc5
v3.13-rc6
v3.13-rc7
v3.13-rc8
v3.14
v3.14-rc1
v3.14-rc2
v3.14-rc3
v3.14-rc4
v3.14-rc5
v3.14-rc6
v3.14-rc7
v3.14-rc8
v3.15
v3.15-rc1
v3.15-rc2
v3.15-rc3
v3.15-rc4
v3.15-rc5
v3.15-rc6
v3.15-rc7
v3.15-rc8
v3.16
v3.16-rc1
v3.16-rc2
v3.16-rc3
v3.16-rc4
v3.16-rc5
v3.16-rc6
v3.16-rc7
v3.17
v3.17-rc1
v3.17-rc2
v3.17-rc3
v3.17-rc4
v3.17-rc5
v3.17-rc6
v3.17-rc7
v3.18
v3.18-rc1
v3.18-rc2
v3.18-rc3
v3.18-rc4
v3.18-rc5
v3.18-rc6
v3.18-rc7
v3.19
v3.19-rc1
v3.19-rc2
v3.19-rc3
v3.19-rc4
v3.19-rc5
v3.19-rc6
v3.19-rc7

v4.*

v4.0
v4.0-rc1
v4.0-rc2
v4.0-rc3
v4.0-rc4
v4.0-rc5
v4.0-rc6
v4.0-rc7
v4.1
v4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1.10
v6.1.11
v6.1.12
v6.1.13
v6.1.14
v6.1.15
v6.1.16
v6.1.17
v6.1.18
v6.1.19
v6.1.2
v6.1.20
v6.1.21
v6.1.22
v6.1.23
v6.1.24
v6.1.25
v6.1.26
v6.1.27
v6.1.28
v6.1.29
v6.1.3
v6.1.4
v6.1.5
v6.1.6
v6.1.7
v6.1.8
v6.1.9
v6.2
v6.2-rc1
v6.2-rc2
v6.2-rc3
v6.2-rc4
v6.2-rc5
v6.2-rc6
v6.2-rc7
v6.2-rc8
v6.3
v6.3-rc1
v6.3-rc2
v6.3-rc3
v6.3-rc4
v6.3-rc5
v6.3-rc6
v6.3-rc7
v6.3.1
v6.3.2
v6.3.3
v6.4-rc1

Database specific

{
    "vanir_signatures": [
        {
            "signature_version": "v1",
            "target": {
                "function": "zswap_writeback_entry",
                "file": "mm/zswap.c"
            },
            "signature_type": "Function",
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@ba700ea13bf0105a4773c654f7d3bef8adb64ab2",
            "deprecated": false,
            "digest": {
                "length": 2117.0,
                "function_hash": "276492150022357947427222559594200768854"
            },
            "id": "CVE-2023-53178-09049385"
        },
        {
            "signature_version": "v1",
            "target": {
                "function": "zswap_writeback_entry",
                "file": "mm/zswap.c"
            },
            "signature_type": "Function",
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@2cab13f500a6333bd2b853783ac76be9e4956f8a",
            "deprecated": false,
            "digest": {
                "length": 2023.0,
                "function_hash": "332166313800090419201489960471523521593"
            },
            "id": "CVE-2023-53178-2b292b65"
        },
        {
            "signature_version": "v1",
            "target": {
                "file": "mm/zswap.c"
            },
            "signature_type": "Line",
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@04fc7816089c5a32c29a04ec94b998e219dfb946",
            "deprecated": false,
            "digest": {
                "line_hashes": [
                    "270897931510983390821172508143958633508",
                    "158700890838025227639261642285697390123",
                    "287631605221437223990527199055239157552",
                    "12215852667165856966825036701112394056"
                ],
                "threshold": 0.9
            },
            "id": "CVE-2023-53178-40415bd4"
        },
        {
            "signature_version": "v1",
            "target": {
                "file": "mm/zswap.c"
            },
            "signature_type": "Line",
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@2cab13f500a6333bd2b853783ac76be9e4956f8a",
            "deprecated": false,
            "digest": {
                "line_hashes": [
                    "270897931510983390821172508143958633508",
                    "158700890838025227639261642285697390123",
                    "287631605221437223990527199055239157552",
                    "84803542191154806927341015593428596527"
                ],
                "threshold": 0.9
            },
            "id": "CVE-2023-53178-5d606fd7"
        },
        {
            "signature_version": "v1",
            "target": {
                "function": "zswap_writeback_entry",
                "file": "mm/zswap.c"
            },
            "signature_type": "Function",
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@04fc7816089c5a32c29a04ec94b998e219dfb946",
            "deprecated": false,
            "digest": {
                "length": 2117.0,
                "function_hash": "276492150022357947427222559594200768854"
            },
            "id": "CVE-2023-53178-dec10a16"
        },
        {
            "signature_version": "v1",
            "target": {
                "file": "mm/zswap.c"
            },
            "signature_type": "Line",
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@ba700ea13bf0105a4773c654f7d3bef8adb64ab2",
            "deprecated": false,
            "digest": {
                "line_hashes": [
                    "270897931510983390821172508143958633508",
                    "158700890838025227639261642285697390123",
                    "287631605221437223990527199055239157552",
                    "12215852667165856966825036701112394056"
                ],
                "threshold": 0.9
            },
            "id": "CVE-2023-53178-e1f1b67a"
        }
    ]
}

Linux / Kernel

Package

Name
Kernel

Affected ranges

Type
ECOSYSTEM
Events
Introduced
3.11.0
Fixed
6.1.30
Type
ECOSYSTEM
Events
Introduced
6.2.0
Fixed
6.3.4