]> Git Repo - linux.git/commitdiff
mm: kfence: fix missing objcg housekeeping for SLAB
authorMuchun Song <[email protected]>
Sun, 27 Mar 2022 05:18:52 +0000 (13:18 +0800)
committerLinus Torvalds <[email protected]>
Mon, 28 Mar 2022 01:47:00 +0000 (18:47 -0700)
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]/
Reported-by: [email protected]
Fixes: d3fb45f370d9 ("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]>
mm/slab.c

index d9dec7a8fd79bfecc02aff59087e6a645c86e80f..b04e40078bdf7d63e540fe20da21049b00779d3a 100644 (file)
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3422,6 +3422,7 @@ static __always_inline void __cache_free(struct kmem_cache *cachep, void *objp,
 
        if (is_kfence_address(objp)) {
                kmemleak_free_recursive(objp, cachep->flags);
+               memcg_slab_free_hook(cachep, &objp, 1);
                __kfence_free(objp);
                return;
        }
This page took 0.058962 seconds and 4 git commands to generate.