linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/slab: always use cache from obj
@ 2023-02-14 10:19 Jiazi.Li
  2023-02-14 10:33 ` Vlastimil Babka
  0 siblings, 1 reply; 5+ messages in thread
From: Jiazi.Li @ 2023-02-14 10:19 UTC (permalink / raw)
  To: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, Vlastimil Babka, Roman Gushchin, Hyeonggon Yoo
  Cc: Jiazi.Li, linux-mm

If free obj to a wrong cache, in addition random, different offset
and object_size will also cause problems:
1. The offset of a cache with a ctor is not zero, free an object from
this cache to cache with offset zero, will write next freepointer to
wrong location, resulting in confusion of freelist.
2. If wrong cache want init on free, and cache->object_size is large
than obj size, which may lead to overwrite issue.

Compared with adding a lot of if-else, it may be better to use obj's
cache directly.

Signed-off-by: Jiazi.Li <jiazi.li@transsion.com>
---
 mm/slab.h | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/mm/slab.h b/mm/slab.h
index 63fb4c00d529..ed39b2e4f27b 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -670,10 +670,6 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
 {
 	struct kmem_cache *cachep;
 
-	if (!IS_ENABLED(CONFIG_SLAB_FREELIST_HARDENED) &&
-	    !kmem_cache_debug_flags(s, SLAB_CONSISTENCY_CHECKS))
-		return s;
-
 	cachep = virt_to_cache(x);
 	if (WARN(cachep && cachep != s,
 		  "%s: Wrong slab cache. %s but object is from %s\n",
-- 
2.17.1



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

end of thread, other threads:[~2023-02-15 10:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14 10:19 [PATCH] mm/slab: always use cache from obj Jiazi.Li
2023-02-14 10:33 ` Vlastimil Babka
2023-02-15  5:49   ` lijiazi
2023-02-15  9:41     ` Vlastimil Babka
2023-02-15 10:03       ` lijiazi

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