mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] mm: kfence: fix missing objcg housekeeping for SLAB
@ 2022-03-27  5:18 Muchun Song
  2022-03-27  5:18 ` [PATCH 2/2] mm: kfence: fix objcgs vector allocation Muchun Song
  2022-03-27 21:08 ` [PATCH 1/2] mm: kfence: fix missing objcg housekeeping for SLAB Linus Torvalds
  0 siblings, 2 replies; 10+ messages in thread
From: Muchun Song @ 2022-03-27  5:18 UTC (permalink / raw)
  To: torvalds, glider, elver, dvyukov, akpm, cl, penberg, rientjes,
	iamjoonsoo.kim, vbabka, roman.gushchin
  Cc: kasan-dev, linux-mm, linux-kernel, Muchun Song,
	syzbot+f8c45ccc7d5d45fc5965

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.

[1] https://groups.google.com/g/syzkaller-bugs/c/BBQFy2QraoY/m/HtBd5gbyAQAJ
Reported-by: syzbot+f8c45ccc7d5d45fc5965@syzkaller.appspotmail.com
Fixes: d3fb45f370d9 ("mm, kfence: insert KFENCE hooks for SLAB")
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 mm/slab.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/slab.c b/mm/slab.c
index d9dec7a8fd79..b04e40078bdf 100644
--- 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;
 	}
-- 
2.11.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-03-28  7:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-27  5:18 [PATCH 1/2] mm: kfence: fix missing objcg housekeeping for SLAB Muchun Song
2022-03-27  5:18 ` [PATCH 2/2] mm: kfence: fix objcgs vector allocation Muchun Song
2022-03-27  5:43   ` Muchun Song
2022-03-27  8:07   ` kernel test robot
2022-03-27  8:07   ` kernel test robot
2022-03-27 17:31   ` Marco Elver
2022-03-28  1:52     ` Muchun Song
2022-03-28  7:01       ` Marco Elver
2022-03-27 21:08 ` [PATCH 1/2] mm: kfence: fix missing objcg housekeeping for SLAB Linus Torvalds
2022-03-28  1:36   ` Muchun Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®