mm: zswap: warn when referencing a dead entry
authorJohannes Weiner <hannes@cmpxchg.org>
Tue, 30 Jan 2024 01:36:40 +0000 (20:36 -0500)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 22 Feb 2024 18:24:42 +0000 (10:24 -0800)
Put a standard sanity check on zswap_entry_get() for UAF scenario.

Link: https://lkml.kernel.org/r/20240130014208.565554-5-hannes@cmpxchg.org
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Nhat Pham <nphamcs@gmail.com>
Acked-by: Yosry Ahmed <yosryahmed@google.com>
Reviewed-by: Chengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/zswap.c

index 0dfd410d1b3c31ade6c5785a1ac365ef73c1ff42..70e409add32b2edd65b35912740d915336ff48b0 100644 (file)
@@ -541,6 +541,7 @@ static void zswap_entry_free(struct zswap_entry *entry)
 /* caller must hold the tree lock */
 static void zswap_entry_get(struct zswap_entry *entry)
 {
+       WARN_ON_ONCE(!entry->refcount);
        entry->refcount++;
 }