Skip to content

Commit ae085d7

Browse files
Muchun Songtorvalds
authored andcommitted
mm: kfence: fix missing objcg housekeeping for SLAB
The objcg is not cleared and put for kfence object when it is freed, which could lead to memory leak for struct obj_cgroup and wrong statistics of NR_SLAB_RECLAIMABLE_B or NR_SLAB_UNRECLAIMABLE_B. Since the last freed object's objcg is not cleared, mem_cgroup_from_obj() could return the wrong memcg when this kfence object, which is not charged to any objcgs, is reallocated to other users. A real word issue [1] is caused by this bug. Link: https://lore.kernel.org/all/[email protected]/ [1] Reported-by: [email protected] Fixes: d3fb45f ("mm, kfence: insert KFENCE hooks for SLAB") Signed-off-by: Muchun Song <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Marco Elver <[email protected]> Cc: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent f82da16 commit ae085d7

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

mm/slab.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,6 +3422,7 @@ static __always_inline void __cache_free(struct kmem_cache *cachep, void *objp,
34223422

34233423
if (is_kfence_address(objp)) {
34243424
kmemleak_free_recursive(objp, cachep->flags);
3425+
memcg_slab_free_hook(cachep, &objp, 1);
34253426
__kfence_free(objp);
34263427
return;
34273428
}

0 commit comments

Comments
 (0)