From 8df273c8566412f09860dd16a4fe6fd2bf4c1a3d Mon Sep 17 00:00:00 2001 From: anupritaisno1 Date: Tue, 7 Dec 2021 05:23:48 +0530 Subject: [PATCH] bug on kmem_cache_free with the wrong cache Signed-off-by: Daniel Micay Signed-off-by: anupritaisno1 --- mm/slab.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/slab.h b/mm/slab.h index 32ccbb32a..ad457ec12 100755 --- a/mm/slab.h +++ b/mm/slab.h @@ -510,10 +510,14 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x) return s; cachep = virt_to_cache(x); +#ifdef CONFIG_BUG_ON_DATA_CORRUPTION + BUG_ON(cachep && cachep != s); +#else if (WARN(cachep && cachep != s, "%s: Wrong slab cache. %s but object is from %s\n", __func__, s->name, cachep->name)) print_tracking(cachep, x); +#endif return cachep; }