KASAN: remove code paths guarded by CONFIG_SLAB
authorVlastimil Babka <vbabka@suse.cz>
Mon, 2 Oct 2023 14:17:16 +0000 (16:17 +0200)
committerVlastimil Babka <vbabka@suse.cz>
Tue, 5 Dec 2023 10:17:51 +0000 (11:17 +0100)
With SLAB removed and SLUB the only remaining allocator, we can clean up
some code that was depending on the choice.

Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Marco Elver <elver@google.com>
Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
Acked-by: David Rientjes <rientjes@google.com>
Tested-by: David Rientjes <rientjes@google.com>
Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
mm/kasan/common.c
mm/kasan/kasan.h
mm/kasan/quarantine.c

index 256930da578a04ba7806682aae7eab46161ce121..5d95219e69d7155cc76226c2bcfceb3b28d536a9 100644 (file)
@@ -153,10 +153,6 @@ void __kasan_poison_object_data(struct kmem_cache *cache, void *object)
  * 2. A cache might be SLAB_TYPESAFE_BY_RCU, which means objects can be
  *    accessed after being freed. We preassign tags for objects in these
  *    caches as well.
- * 3. For SLAB allocator we can't preassign tags randomly since the freelist
- *    is stored as an array of indexes instead of a linked list. Assign tags
- *    based on objects indexes, so that objects that are next to each other
- *    get different tags.
  */
 static inline u8 assign_tag(struct kmem_cache *cache,
                                        const void *object, bool init)
@@ -171,17 +167,12 @@ static inline u8 assign_tag(struct kmem_cache *cache,
        if (!cache->ctor && !(cache->flags & SLAB_TYPESAFE_BY_RCU))
                return init ? KASAN_TAG_KERNEL : kasan_random_tag();
 
-       /* For caches that either have a constructor or SLAB_TYPESAFE_BY_RCU: */
-#ifdef CONFIG_SLAB
-       /* For SLAB assign tags based on the object index in the freelist. */
-       return (u8)obj_to_index(cache, virt_to_slab(object), (void *)object);
-#else
        /*
-        * For SLUB assign a random tag during slab creation, otherwise reuse
+        * For caches that either have a constructor or SLAB_TYPESAFE_BY_RCU,
+        * assign a random tag during slab creation, otherwise reuse
         * the already assigned tag.
         */
        return init ? kasan_random_tag() : get_tag(object);
-#endif
 }
 
 void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache,
index 8b06bab5c4066c02d4003887acd6264a6748195d..eef50233640a5b191c62616126f62c44eb5d2094 100644 (file)
@@ -373,8 +373,7 @@ void kasan_set_track(struct kasan_track *track, gfp_t flags);
 void kasan_save_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags);
 void kasan_save_free_info(struct kmem_cache *cache, void *object);
 
-#if defined(CONFIG_KASAN_GENERIC) && \
-       (defined(CONFIG_SLAB) || defined(CONFIG_SLUB))
+#ifdef CONFIG_KASAN_GENERIC
 bool kasan_quarantine_put(struct kmem_cache *cache, void *object);
 void kasan_quarantine_reduce(void);
 void kasan_quarantine_remove_cache(struct kmem_cache *cache);
index ca4529156735920f450f4b960fe08578ace0dbae..138c57b836f2783f524850b809df1b63cc63c14d 100644 (file)
@@ -144,10 +144,6 @@ static void qlink_free(struct qlist_node *qlink, struct kmem_cache *cache)
 {
        void *object = qlink_to_object(qlink, cache);
        struct kasan_free_meta *meta = kasan_get_free_meta(cache, object);
-       unsigned long flags;
-
-       if (IS_ENABLED(CONFIG_SLAB))
-               local_irq_save(flags);
 
        /*
         * If init_on_free is enabled and KASAN's free metadata is stored in
@@ -166,9 +162,6 @@ static void qlink_free(struct qlist_node *qlink, struct kmem_cache *cache)
        *(u8 *)kasan_mem_to_shadow(object) = KASAN_SLAB_FREE;
 
        ___cache_free(cache, object, _THIS_IP_);
-
-       if (IS_ENABLED(CONFIG_SLAB))
-               local_irq_restore(flags);
 }
 
 static void qlist_free_all(struct qlist_head *q, struct kmem_cache *cache)