@@ -325,18 +341,41 @@ void kasan_init_slab_obj(struct kmem_cache *cache, const void *object)This seams breaking the kmem_cache_create() contract: "The @ctor is run when new pages are allocated by the cache." (https://elixir.bootlin.com/linux/v3.7/source/mm/slab_common.c#L83)
void *kasan_slab_alloc(struct kmem_cache *cache, void *object, gfp_t flags)
{
- return kasan_kmalloc(cache, object, cache->object_size, flags);
+ object = kasan_kmalloc(cache, object, cache->object_size, flags);
+ if (IS_ENABLED(CONFIG_KASAN_HW) && unlikely(cache->ctor)) {
+ /*
+ * Cache constructor might use object's pointer value to
+ * initialize some of its fields.
+ */
+ cache->ctor(object);