Message ID | cfc1744f4a5eb6f50eddee53238af1a2fb4e8583.1655150842.git.andreyknvl@google.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | kasan: switch tag-based modes to stack ring from per-object metadata | expand |
On Mon, 13 Jun 2022 at 22:15, <andrey.konovalov@linux.dev> wrote: > > From: Andrey Konovalov <andreyknvl@google.com> > > Drop CONFIG_KASAN_TAGS_IDENTIFY and related code to simplify making > changes to the reporting code. > > The dropped functionality will be restored in the following patches in > this series. > > Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Reviewed-by: Marco Elver <elver@google.com> > --- > lib/Kconfig.kasan | 8 -------- > mm/kasan/kasan.h | 12 +----------- > mm/kasan/report_tags.c | 28 ---------------------------- > mm/kasan/tags.c | 21 ++------------------- > 4 files changed, 3 insertions(+), 66 deletions(-) > > diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan > index f0973da583e0..ca09b1cf8ee9 100644 > --- a/lib/Kconfig.kasan > +++ b/lib/Kconfig.kasan > @@ -167,14 +167,6 @@ config KASAN_STACK > as well, as it adds inline-style instrumentation that is run > unconditionally. > > -config KASAN_TAGS_IDENTIFY > - bool "Memory corruption type identification" > - depends on KASAN_SW_TAGS || KASAN_HW_TAGS > - help > - Enables best-effort identification of the bug types (use-after-free > - or out-of-bounds) at the cost of increased memory consumption. > - Only applicable for the tag-based KASAN modes. > - > config KASAN_VMALLOC > bool "Check accesses to vmalloc allocations" > depends on HAVE_ARCH_KASAN_VMALLOC > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > index 610057e651d2..aa6b43936f8d 100644 > --- a/mm/kasan/kasan.h > +++ b/mm/kasan/kasan.h > @@ -168,23 +168,13 @@ struct kasan_track { > depot_stack_handle_t stack; > }; > > -#if defined(CONFIG_KASAN_TAGS_IDENTIFY) && defined(CONFIG_KASAN_SW_TAGS) > -#define KASAN_NR_FREE_STACKS 5 > -#else > -#define KASAN_NR_FREE_STACKS 1 > -#endif > - > struct kasan_alloc_meta { > struct kasan_track alloc_track; > /* Generic mode stores free track in kasan_free_meta. */ > #ifdef CONFIG_KASAN_GENERIC > depot_stack_handle_t aux_stack[2]; > #else > - struct kasan_track free_track[KASAN_NR_FREE_STACKS]; > -#endif > -#ifdef CONFIG_KASAN_TAGS_IDENTIFY > - u8 free_pointer_tag[KASAN_NR_FREE_STACKS]; > - u8 free_track_idx; > + struct kasan_track free_track; > #endif > }; > > diff --git a/mm/kasan/report_tags.c b/mm/kasan/report_tags.c > index e25d2166e813..35cf3cae4aa4 100644 > --- a/mm/kasan/report_tags.c > +++ b/mm/kasan/report_tags.c > @@ -5,37 +5,9 @@ > */ > > #include "kasan.h" > -#include "../slab.h" > > const char *kasan_get_bug_type(struct kasan_report_info *info) > { > -#ifdef CONFIG_KASAN_TAGS_IDENTIFY > - struct kasan_alloc_meta *alloc_meta; > - struct kmem_cache *cache; > - struct slab *slab; > - const void *addr; > - void *object; > - u8 tag; > - int i; > - > - tag = get_tag(info->access_addr); > - addr = kasan_reset_tag(info->access_addr); > - slab = kasan_addr_to_slab(addr); > - if (slab) { > - cache = slab->slab_cache; > - object = nearest_obj(cache, slab, (void *)addr); > - alloc_meta = kasan_get_alloc_meta(cache, object); > - > - if (alloc_meta) { > - for (i = 0; i < KASAN_NR_FREE_STACKS; i++) { > - if (alloc_meta->free_pointer_tag[i] == tag) > - return "use-after-free"; > - } > - } > - return "out-of-bounds"; > - } > -#endif > - > /* > * If access_size is a negative number, then it has reason to be > * defined as out-of-bounds bug type. > diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c > index 1ba3c8399f72..e0e5de8ce834 100644 > --- a/mm/kasan/tags.c > +++ b/mm/kasan/tags.c > @@ -30,39 +30,22 @@ void kasan_save_free_info(struct kmem_cache *cache, > void *object, u8 tag) > { > struct kasan_alloc_meta *alloc_meta; > - u8 idx = 0; > > alloc_meta = kasan_get_alloc_meta(cache, object); > if (!alloc_meta) > return; > > -#ifdef CONFIG_KASAN_TAGS_IDENTIFY > - idx = alloc_meta->free_track_idx; > - alloc_meta->free_pointer_tag[idx] = tag; > - alloc_meta->free_track_idx = (idx + 1) % KASAN_NR_FREE_STACKS; > -#endif > - > - kasan_set_track(&alloc_meta->free_track[idx], GFP_NOWAIT); > + kasan_set_track(&alloc_meta->free_track, GFP_NOWAIT); > } > > struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, > void *object, u8 tag) > { > struct kasan_alloc_meta *alloc_meta; > - int i = 0; > > alloc_meta = kasan_get_alloc_meta(cache, object); > if (!alloc_meta) > return NULL; > > -#ifdef CONFIG_KASAN_TAGS_IDENTIFY > - for (i = 0; i < KASAN_NR_FREE_STACKS; i++) { > - if (alloc_meta->free_pointer_tag[i] == tag) > - break; > - } > - if (i == KASAN_NR_FREE_STACKS) > - i = alloc_meta->free_track_idx; > -#endif > - > - return &alloc_meta->free_track[i]; > + return &alloc_meta->free_track; > } > -- > 2.25.1 > > -- > You received this message because you are subscribed to the Google Groups "kasan-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/cfc1744f4a5eb6f50eddee53238af1a2fb4e8583.1655150842.git.andreyknvl%40google.com.
diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index f0973da583e0..ca09b1cf8ee9 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -167,14 +167,6 @@ config KASAN_STACK as well, as it adds inline-style instrumentation that is run unconditionally. -config KASAN_TAGS_IDENTIFY - bool "Memory corruption type identification" - depends on KASAN_SW_TAGS || KASAN_HW_TAGS - help - Enables best-effort identification of the bug types (use-after-free - or out-of-bounds) at the cost of increased memory consumption. - Only applicable for the tag-based KASAN modes. - config KASAN_VMALLOC bool "Check accesses to vmalloc allocations" depends on HAVE_ARCH_KASAN_VMALLOC diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 610057e651d2..aa6b43936f8d 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -168,23 +168,13 @@ struct kasan_track { depot_stack_handle_t stack; }; -#if defined(CONFIG_KASAN_TAGS_IDENTIFY) && defined(CONFIG_KASAN_SW_TAGS) -#define KASAN_NR_FREE_STACKS 5 -#else -#define KASAN_NR_FREE_STACKS 1 -#endif - struct kasan_alloc_meta { struct kasan_track alloc_track; /* Generic mode stores free track in kasan_free_meta. */ #ifdef CONFIG_KASAN_GENERIC depot_stack_handle_t aux_stack[2]; #else - struct kasan_track free_track[KASAN_NR_FREE_STACKS]; -#endif -#ifdef CONFIG_KASAN_TAGS_IDENTIFY - u8 free_pointer_tag[KASAN_NR_FREE_STACKS]; - u8 free_track_idx; + struct kasan_track free_track; #endif }; diff --git a/mm/kasan/report_tags.c b/mm/kasan/report_tags.c index e25d2166e813..35cf3cae4aa4 100644 --- a/mm/kasan/report_tags.c +++ b/mm/kasan/report_tags.c @@ -5,37 +5,9 @@ */ #include "kasan.h" -#include "../slab.h" const char *kasan_get_bug_type(struct kasan_report_info *info) { -#ifdef CONFIG_KASAN_TAGS_IDENTIFY - struct kasan_alloc_meta *alloc_meta; - struct kmem_cache *cache; - struct slab *slab; - const void *addr; - void *object; - u8 tag; - int i; - - tag = get_tag(info->access_addr); - addr = kasan_reset_tag(info->access_addr); - slab = kasan_addr_to_slab(addr); - if (slab) { - cache = slab->slab_cache; - object = nearest_obj(cache, slab, (void *)addr); - alloc_meta = kasan_get_alloc_meta(cache, object); - - if (alloc_meta) { - for (i = 0; i < KASAN_NR_FREE_STACKS; i++) { - if (alloc_meta->free_pointer_tag[i] == tag) - return "use-after-free"; - } - } - return "out-of-bounds"; - } -#endif - /* * If access_size is a negative number, then it has reason to be * defined as out-of-bounds bug type. diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c index 1ba3c8399f72..e0e5de8ce834 100644 --- a/mm/kasan/tags.c +++ b/mm/kasan/tags.c @@ -30,39 +30,22 @@ void kasan_save_free_info(struct kmem_cache *cache, void *object, u8 tag) { struct kasan_alloc_meta *alloc_meta; - u8 idx = 0; alloc_meta = kasan_get_alloc_meta(cache, object); if (!alloc_meta) return; -#ifdef CONFIG_KASAN_TAGS_IDENTIFY - idx = alloc_meta->free_track_idx; - alloc_meta->free_pointer_tag[idx] = tag; - alloc_meta->free_track_idx = (idx + 1) % KASAN_NR_FREE_STACKS; -#endif - - kasan_set_track(&alloc_meta->free_track[idx], GFP_NOWAIT); + kasan_set_track(&alloc_meta->free_track, GFP_NOWAIT); } struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, void *object, u8 tag) { struct kasan_alloc_meta *alloc_meta; - int i = 0; alloc_meta = kasan_get_alloc_meta(cache, object); if (!alloc_meta) return NULL; -#ifdef CONFIG_KASAN_TAGS_IDENTIFY - for (i = 0; i < KASAN_NR_FREE_STACKS; i++) { - if (alloc_meta->free_pointer_tag[i] == tag) - break; - } - if (i == KASAN_NR_FREE_STACKS) - i = alloc_meta->free_track_idx; -#endif - - return &alloc_meta->free_track[i]; + return &alloc_meta->free_track; }