Skip to content

Commit 2e601e1

Browse files
hnazakpm00
authored andcommitted
mm: zswap: fix objcg use-after-free in entry destruction
In the per-memcg LRU universe, LRU removal uses entry->objcg to determine which list count needs to be decreased. Drop the objcg reference after updating the LRU, to fix a possible use-after-free. Link: https://lkml.kernel.org/r/20240130013438.565167-1-hannes@cmpxchg.org Fixes: a65b0e7 ("zswap: make shrinking memcg-aware") Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Yosry Ahmed <yosryahmed@google.com> Reviewed-by: Nhat Pham <nphamcs@gmail.com> Reviewed-by: Chengming Zhou <zhouchengming@bytedance.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 4c2da31 commit 2e601e1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mm/zswap.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,6 @@ static struct zpool *zswap_find_zpool(struct zswap_entry *entry)
536536
*/
537537
static void zswap_free_entry(struct zswap_entry *entry)
538538
{
539-
if (entry->objcg) {
540-
obj_cgroup_uncharge_zswap(entry->objcg, entry->length);
541-
obj_cgroup_put(entry->objcg);
542-
}
543539
if (!entry->length)
544540
atomic_dec(&zswap_same_filled_pages);
545541
else {
@@ -548,6 +544,10 @@ static void zswap_free_entry(struct zswap_entry *entry)
548544
atomic_dec(&entry->pool->nr_stored);
549545
zswap_pool_put(entry->pool);
550546
}
547+
if (entry->objcg) {
548+
obj_cgroup_uncharge_zswap(entry->objcg, entry->length);
549+
obj_cgroup_put(entry->objcg);
550+
}
551551
zswap_entry_cache_free(entry);
552552
atomic_dec(&zswap_stored_pages);
553553
zswap_update_total_size();

0 commit comments

Comments
 (0)