Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 189A43101B8 for ; Mon, 15 Sep 2025 14:11:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757945476; cv=none; b=idsxAoftjh1A8paZecis+jB6wAsclQJKlxBs2m5P4aQBw0jls2eoG7UZwCGuqgBnwG2bOUylJbCv34ovxnlXkgJQErPNqVCBjQRxkBXmkm5ZKXKbE/LwE6qc+Xw6FPNG3/TxpHeVdvtJ1obdyj+Bj6wbVVoqmWUBK+YtMRip+P4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757945476; c=relaxed/simple; bh=6Qzoi44hkM9xJTJBLNHleEDk01KUBmULKqz3B06O+lk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fDmbwfW7SxXgMiJglzth6Mc/bFnYRB1qsZ6EPHtpvn8yAIuv+v3S9rsNI6/iEE8V4sa36rTyMtsnWk/FeWCpJakSjTfL92SDFgnrkppzPil7W2dHTyNcX3yjia7UT4Ffmk/TloU08WlmeBLbZKTZzk7GnOsy8ZOHCJuWiOB02ZM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CBtlKpbs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CBtlKpbs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E076C4CEF1; Mon, 15 Sep 2025 14:11:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1757945475; bh=6Qzoi44hkM9xJTJBLNHleEDk01KUBmULKqz3B06O+lk=; h=From:To:Cc:Subject:Date:Reply-to:From; b=CBtlKpbseNtW4fPkAFwXXJ212dvdGB4NJg7QiGuHHxKqVztESck8o9OJZfOA1df1d uBmTF/9FhKg4z4MK2KisaPhAi4uj3l2bYQ0+X6o7wLcyjlhIj9GJCzHnakp4cqmgbi EQhqpGu7Zkbd5PmSp2Afr5cTkWKoFN/HGLliYwNU= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2023-53178: mm: fix zswap writeback race condition Date: Mon, 15 Sep 2025 16:02:32 +0200 Message-ID: <2025091555-CVE-2023-53178-9d27@gregkh> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=3830; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=UgcfawEyC7UQhj2W7AVK4sLChBY5M94sYilfYQDKc/Y=; b=owGbwMvMwCRo6H6F97bub03G02pJDBknZILZreKzz+fXTTO7Uuxsk8uvIeBw4+a/xzcnzooLZ kmfMHtDRywLgyATg6yYIsuXbTxH91ccUvQytD0NM4eVCWQIAxenAEzEdwXDPF1DXsMtN1aeSLvw 3LAgzepRmeOhToYFl8pey/odmrxg+4577gvuz//S9YrbDAA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit From: Greg Kroah-Hartman Description =========== 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 ZSWAP_SWAPCACHE_NEW), 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/written_back_pages 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/max_pool_percent 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. The Linux kernel CVE team has assigned CVE-2023-53178 to this issue. Affected and fixed versions =========================== Fixed in 6.1.30 with commit 2cab13f500a6333bd2b853783ac76be9e4956f8a Fixed in 6.3.4 with commit ba700ea13bf0105a4773c654f7d3bef8adb64ab2 Fixed in 6.4 with commit 04fc7816089c5a32c29a04ec94b998e219dfb946 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2023-53178 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: mm/zswap.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/2cab13f500a6333bd2b853783ac76be9e4956f8a https://git.kernel.org/stable/c/ba700ea13bf0105a4773c654f7d3bef8adb64ab2 https://git.kernel.org/stable/c/04fc7816089c5a32c29a04ec94b998e219dfb946