lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230922172211.1704917-1-cerasuolodomenico@gmail.com>
Date:   Fri, 22 Sep 2023 19:22:11 +0200
From:   Domenico Cerasuolo <cerasuolodomenico@...il.com>
To:     sjenning@...hat.com, ddstreet@...e.org, vitaly.wool@...sulko.com,
        akpm@...ux-foundation.org, nphamcs@...il.com, hannes@...xchg.org
Cc:     linux-mm@...ck.org, linux-kernel@...r.kernel.org,
        kernel-team@...a.com,
        Domenico Cerasuolo <cerasuolodomenico@...il.com>
Subject: [PATCH] mm: zswap: fix potential memory corruption on duplicate store

While stress-testing zswap a memory corruption was happening when writing
back pages. __frontswap_store used to check for duplicate entries before
attempting to store a page in zswap, this was because if the store fails
the old entry isn't removed from the tree. This change removes duplicate
entries in zswap_store before the actual attempt.

Based on commit ce9ecca0238b ("Linux 6.6-rc2")

Fixes: 42c06a0e8ebe ("mm: kill frontswap")
Signed-off-by: Domenico Cerasuolo <cerasuolodomenico@...il.com>
---
 mm/zswap.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/mm/zswap.c b/mm/zswap.c
index 412b1409a0d7..9146f9f19061 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -1218,6 +1218,19 @@ bool zswap_store(struct folio *folio)
 	if (!zswap_enabled || !tree)
 		return false;
 
+	/*
+	 * If this is a duplicate, it must be removed before attempting to store
+	 * it, otherwise, if the store fails the old page won't be removed from
+	 * the tree, and it might be written back overriding the new data.
+	 */
+	spin_lock(&tree->lock);
+	dupentry = zswap_rb_search(&tree->rbroot, offset);
+	if (dupentry) {
+		zswap_duplicate_entry++;
+		zswap_invalidate_entry(tree, dupentry);
+	}
+	spin_unlock(&tree->lock);
+
 	/*
 	 * XXX: zswap reclaim does not work with cgroups yet. Without a
 	 * cgroup-aware entry LRU, we will push out entries system-wide based on
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ