Message ID | ae1389c0717d1875077ee3f6cd4beb5b7e046ae0.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> > > Provide standalone implementations of save_alloc_info() for the Generic > and tag-based modes. > > For now, the implementations are the same, but they will diverge later > in the series. > > Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Reviewed-by: Marco Elver <elver@google.com> > --- > mm/kasan/common.c | 13 ++----------- > mm/kasan/generic.c | 9 +++++++++ > mm/kasan/kasan.h | 1 + > mm/kasan/tags.c | 9 +++++++++ > 4 files changed, 21 insertions(+), 11 deletions(-) > > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index a6107e8375e0..2848c7a2402a 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -423,15 +423,6 @@ void __kasan_slab_free_mempool(void *ptr, unsigned long ip) > } > } > > -static void save_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) > -{ > - struct kasan_alloc_meta *alloc_meta; > - > - alloc_meta = kasan_get_alloc_meta(cache, object); > - if (alloc_meta) > - kasan_set_track(&alloc_meta->alloc_track, flags); > -} > - > void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, > void *object, gfp_t flags, bool init) > { > @@ -462,7 +453,7 @@ void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, > > /* Save alloc info (if possible) for non-kmalloc() allocations. */ > if (kasan_stack_collection_enabled() && !cache->kasan_info.is_kmalloc) > - save_alloc_info(cache, (void *)object, flags); > + kasan_save_alloc_info(cache, (void *)object, flags); > > return tagged_object; > } > @@ -508,7 +499,7 @@ static inline void *____kasan_kmalloc(struct kmem_cache *cache, > * This also rewrites the alloc info when called from kasan_krealloc(). > */ > if (kasan_stack_collection_enabled() && cache->kasan_info.is_kmalloc) > - save_alloc_info(cache, (void *)object, flags); > + kasan_save_alloc_info(cache, (void *)object, flags); > > /* Keep the tag that was set by kasan_slab_alloc(). */ > return (void *)object; > diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c > index 03a3770cfeae..98c451a3b01f 100644 > --- a/mm/kasan/generic.c > +++ b/mm/kasan/generic.c > @@ -358,6 +358,15 @@ void kasan_record_aux_stack_noalloc(void *addr) > return __kasan_record_aux_stack(addr, false); > } > > +void kasan_save_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) > +{ > + struct kasan_alloc_meta *alloc_meta; > + > + alloc_meta = kasan_get_alloc_meta(cache, object); > + if (alloc_meta) > + kasan_set_track(&alloc_meta->alloc_track, flags); > +} > + > void kasan_save_free_info(struct kmem_cache *cache, > void *object, u8 tag) > { > diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h > index 6df8d7b01073..610057e651d2 100644 > --- a/mm/kasan/kasan.h > +++ b/mm/kasan/kasan.h > @@ -284,6 +284,7 @@ struct slab *kasan_addr_to_slab(const void *addr); > > depot_stack_handle_t kasan_save_stack(gfp_t flags, bool can_alloc); > 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, u8 tag); > struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, > void *object, u8 tag); > diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c > index b453a353bc86..1ba3c8399f72 100644 > --- a/mm/kasan/tags.c > +++ b/mm/kasan/tags.c > @@ -17,6 +17,15 @@ > > #include "kasan.h" > > +void kasan_save_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) > +{ > + struct kasan_alloc_meta *alloc_meta; > + > + alloc_meta = kasan_get_alloc_meta(cache, object); > + if (alloc_meta) > + kasan_set_track(&alloc_meta->alloc_track, flags); > +} > + > void kasan_save_free_info(struct kmem_cache *cache, > void *object, u8 tag) > { > -- > 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/ae1389c0717d1875077ee3f6cd4beb5b7e046ae0.1655150842.git.andreyknvl%40google.com.
diff --git a/mm/kasan/common.c b/mm/kasan/common.c index a6107e8375e0..2848c7a2402a 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -423,15 +423,6 @@ void __kasan_slab_free_mempool(void *ptr, unsigned long ip) } } -static void save_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) -{ - struct kasan_alloc_meta *alloc_meta; - - alloc_meta = kasan_get_alloc_meta(cache, object); - if (alloc_meta) - kasan_set_track(&alloc_meta->alloc_track, flags); -} - void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, void *object, gfp_t flags, bool init) { @@ -462,7 +453,7 @@ void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, /* Save alloc info (if possible) for non-kmalloc() allocations. */ if (kasan_stack_collection_enabled() && !cache->kasan_info.is_kmalloc) - save_alloc_info(cache, (void *)object, flags); + kasan_save_alloc_info(cache, (void *)object, flags); return tagged_object; } @@ -508,7 +499,7 @@ static inline void *____kasan_kmalloc(struct kmem_cache *cache, * This also rewrites the alloc info when called from kasan_krealloc(). */ if (kasan_stack_collection_enabled() && cache->kasan_info.is_kmalloc) - save_alloc_info(cache, (void *)object, flags); + kasan_save_alloc_info(cache, (void *)object, flags); /* Keep the tag that was set by kasan_slab_alloc(). */ return (void *)object; diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 03a3770cfeae..98c451a3b01f 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -358,6 +358,15 @@ void kasan_record_aux_stack_noalloc(void *addr) return __kasan_record_aux_stack(addr, false); } +void kasan_save_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) +{ + struct kasan_alloc_meta *alloc_meta; + + alloc_meta = kasan_get_alloc_meta(cache, object); + if (alloc_meta) + kasan_set_track(&alloc_meta->alloc_track, flags); +} + void kasan_save_free_info(struct kmem_cache *cache, void *object, u8 tag) { diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 6df8d7b01073..610057e651d2 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -284,6 +284,7 @@ struct slab *kasan_addr_to_slab(const void *addr); depot_stack_handle_t kasan_save_stack(gfp_t flags, bool can_alloc); 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, u8 tag); struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, void *object, u8 tag); diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c index b453a353bc86..1ba3c8399f72 100644 --- a/mm/kasan/tags.c +++ b/mm/kasan/tags.c @@ -17,6 +17,15 @@ #include "kasan.h" +void kasan_save_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) +{ + struct kasan_alloc_meta *alloc_meta; + + alloc_meta = kasan_get_alloc_meta(cache, object); + if (alloc_meta) + kasan_set_track(&alloc_meta->alloc_track, flags); +} + void kasan_save_free_info(struct kmem_cache *cache, void *object, u8 tag) {