From: js1304@gmail.com To: Andrew Morton <akpm@linux-foundation.org> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>, Alexander Potapenko <glider@google.com>, Dmitry Vyukov <dvyukov@google.com>, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Namhyung Kim <namhyung@kernel.org>, Wengang Wang <wen.gang.wang@oracle.com>, Joonsoo Kim <iamjoonsoo.kim@lge.com> Subject: [PATCH 04/18] vchecker: prepare per object memory for vchecker Date: Tue, 28 Nov 2017 16:48:39 +0900 [thread overview] Message-ID: <1511855333-3570-5-git-send-email-iamjoonsoo.kim@lge.com> (raw) In-Reply-To: <1511855333-3570-1-git-send-email-iamjoonsoo.kim@lge.com> From: Joonsoo Kim <iamjoonsoo.kim@lge.com> To prepare per object memory for vchecker, we need to change the layout of the object when kmem_cache initialization. Add such code on vchecker_cache_create() which is called when kmem_cache initialization. And, this memory should be initialized when object is populated. Do it with another hook. This memory will be used in the following patch. Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> --- mm/kasan/vchecker.c | 15 +++++++++++++++ mm/kasan/vchecker.h | 4 ++++ mm/slab.c | 2 ++ mm/slub.c | 2 ++ 4 files changed, 23 insertions(+) diff --git a/mm/kasan/vchecker.c b/mm/kasan/vchecker.c index 0b8a1e7..be0f0cd 100644 --- a/mm/kasan/vchecker.c +++ b/mm/kasan/vchecker.c @@ -31,6 +31,10 @@ enum vchecker_type_num { VCHECKER_TYPE_MAX, }; +struct vchecker_data { + void *dummy; +}; + struct vchecker_type { char *name; const struct file_operations *fops; @@ -109,10 +113,21 @@ static int remove_cbs(struct kmem_cache *s, struct vchecker_type *t) return 0; } +void vchecker_init_slab_obj(struct kmem_cache *s, const void *object) +{ + struct vchecker_data *data; + + data = (void *)object + s->vchecker_cache.data_offset; + __memset(data, 0, sizeof(*data)); +} + void vchecker_cache_create(struct kmem_cache *s, size_t *size, slab_flags_t *flags) { *flags |= SLAB_VCHECKER; + + s->vchecker_cache.data_offset = *size; + *size += sizeof(struct vchecker_data); } void vchecker_kmalloc(struct kmem_cache *s, const void *object, size_t size) diff --git a/mm/kasan/vchecker.h b/mm/kasan/vchecker.h index aa22e8d..efebc63 100644 --- a/mm/kasan/vchecker.h +++ b/mm/kasan/vchecker.h @@ -7,6 +7,7 @@ struct vchecker_cb; struct vchecker_cache { struct vchecker *checker; struct dentry *dir; + int data_offset; }; @@ -18,6 +19,7 @@ int init_vchecker(struct kmem_cache *s); void fini_vchecker(struct kmem_cache *s); void vchecker_cache_create(struct kmem_cache *s, size_t *size, slab_flags_t *flags); +void vchecker_init_slab_obj(struct kmem_cache *s, const void *object); void vchecker_enable_cache(struct kmem_cache *s, bool enable); void vchecker_enable_obj(struct kmem_cache *s, const void *object, size_t size, bool enable); @@ -31,6 +33,8 @@ static inline int init_vchecker(struct kmem_cache *s) { return 0; } static inline void fini_vchecker(struct kmem_cache *s) { } static inline void vchecker_cache_create(struct kmem_cache *s, size_t *size, slab_flags_t *flags) {} +static inline void vchecker_init_slab_obj(struct kmem_cache *s, + const void *object) {} #endif diff --git a/mm/slab.c b/mm/slab.c index ba45c15..64d768b 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -2076,6 +2076,7 @@ int __kmem_cache_create(struct kmem_cache *cachep, slab_flags_t flags) } #endif + vchecker_cache_create(cachep, &size, &flags); kasan_cache_create(cachep, &size, &flags); size = ALIGN(size, cachep->align); @@ -2601,6 +2602,7 @@ static void cache_init_objs(struct kmem_cache *cachep, for (i = 0; i < cachep->num; i++) { objp = index_to_obj(cachep, page, i); + vchecker_init_slab_obj(cachep, objp); kasan_init_slab_obj(cachep, objp); /* constructor could break poison info */ diff --git a/mm/slub.c b/mm/slub.c index 67364cb..c099b33 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1418,6 +1418,7 @@ static void setup_object(struct kmem_cache *s, struct page *page, void *object) { setup_object_debug(s, page, object); + vchecker_init_slab_obj(s, object); kasan_init_slab_obj(s, object); if (unlikely(s->ctor)) { kasan_unpoison_object_data(s, object); @@ -3550,6 +3551,7 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order) size += 2 * sizeof(struct track); #endif + vchecker_cache_create(s, &size, &s->flags); kasan_cache_create(s, &size, &s->flags); #ifdef CONFIG_SLUB_DEBUG if (flags & SLAB_RED_ZONE) { -- 2.7.4
WARNING: multiple messages have this Message-ID (diff)
From: js1304@gmail.com To: Andrew Morton <akpm@linux-foundation.org> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>, Alexander Potapenko <glider@google.com>, Dmitry Vyukov <dvyukov@google.com>, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Namhyung Kim <namhyung@kernel.org>, Wengang Wang <wen.gang.wang@oracle.com>, Joonsoo Kim <iamjoonsoo.kim@lge.com> Subject: [PATCH 04/18] vchecker: prepare per object memory for vchecker Date: Tue, 28 Nov 2017 16:48:39 +0900 [thread overview] Message-ID: <1511855333-3570-5-git-send-email-iamjoonsoo.kim@lge.com> (raw) In-Reply-To: <1511855333-3570-1-git-send-email-iamjoonsoo.kim@lge.com> From: Joonsoo Kim <iamjoonsoo.kim@lge.com> To prepare per object memory for vchecker, we need to change the layout of the object when kmem_cache initialization. Add such code on vchecker_cache_create() which is called when kmem_cache initialization. And, this memory should be initialized when object is populated. Do it with another hook. This memory will be used in the following patch. Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> --- mm/kasan/vchecker.c | 15 +++++++++++++++ mm/kasan/vchecker.h | 4 ++++ mm/slab.c | 2 ++ mm/slub.c | 2 ++ 4 files changed, 23 insertions(+) diff --git a/mm/kasan/vchecker.c b/mm/kasan/vchecker.c index 0b8a1e7..be0f0cd 100644 --- a/mm/kasan/vchecker.c +++ b/mm/kasan/vchecker.c @@ -31,6 +31,10 @@ enum vchecker_type_num { VCHECKER_TYPE_MAX, }; +struct vchecker_data { + void *dummy; +}; + struct vchecker_type { char *name; const struct file_operations *fops; @@ -109,10 +113,21 @@ static int remove_cbs(struct kmem_cache *s, struct vchecker_type *t) return 0; } +void vchecker_init_slab_obj(struct kmem_cache *s, const void *object) +{ + struct vchecker_data *data; + + data = (void *)object + s->vchecker_cache.data_offset; + __memset(data, 0, sizeof(*data)); +} + void vchecker_cache_create(struct kmem_cache *s, size_t *size, slab_flags_t *flags) { *flags |= SLAB_VCHECKER; + + s->vchecker_cache.data_offset = *size; + *size += sizeof(struct vchecker_data); } void vchecker_kmalloc(struct kmem_cache *s, const void *object, size_t size) diff --git a/mm/kasan/vchecker.h b/mm/kasan/vchecker.h index aa22e8d..efebc63 100644 --- a/mm/kasan/vchecker.h +++ b/mm/kasan/vchecker.h @@ -7,6 +7,7 @@ struct vchecker_cb; struct vchecker_cache { struct vchecker *checker; struct dentry *dir; + int data_offset; }; @@ -18,6 +19,7 @@ int init_vchecker(struct kmem_cache *s); void fini_vchecker(struct kmem_cache *s); void vchecker_cache_create(struct kmem_cache *s, size_t *size, slab_flags_t *flags); +void vchecker_init_slab_obj(struct kmem_cache *s, const void *object); void vchecker_enable_cache(struct kmem_cache *s, bool enable); void vchecker_enable_obj(struct kmem_cache *s, const void *object, size_t size, bool enable); @@ -31,6 +33,8 @@ static inline int init_vchecker(struct kmem_cache *s) { return 0; } static inline void fini_vchecker(struct kmem_cache *s) { } static inline void vchecker_cache_create(struct kmem_cache *s, size_t *size, slab_flags_t *flags) {} +static inline void vchecker_init_slab_obj(struct kmem_cache *s, + const void *object) {} #endif diff --git a/mm/slab.c b/mm/slab.c index ba45c15..64d768b 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -2076,6 +2076,7 @@ int __kmem_cache_create(struct kmem_cache *cachep, slab_flags_t flags) } #endif + vchecker_cache_create(cachep, &size, &flags); kasan_cache_create(cachep, &size, &flags); size = ALIGN(size, cachep->align); @@ -2601,6 +2602,7 @@ static void cache_init_objs(struct kmem_cache *cachep, for (i = 0; i < cachep->num; i++) { objp = index_to_obj(cachep, page, i); + vchecker_init_slab_obj(cachep, objp); kasan_init_slab_obj(cachep, objp); /* constructor could break poison info */ diff --git a/mm/slub.c b/mm/slub.c index 67364cb..c099b33 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1418,6 +1418,7 @@ static void setup_object(struct kmem_cache *s, struct page *page, void *object) { setup_object_debug(s, page, object); + vchecker_init_slab_obj(s, object); kasan_init_slab_obj(s, object); if (unlikely(s->ctor)) { kasan_unpoison_object_data(s, object); @@ -3550,6 +3551,7 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order) size += 2 * sizeof(struct track); #endif + vchecker_cache_create(s, &size, &s->flags); kasan_cache_create(s, &size, &s->flags); #ifdef CONFIG_SLUB_DEBUG if (flags & SLAB_RED_ZONE) { -- 2.7.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-11-28 7:53 UTC|newest] Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-11-28 7:48 [PATCH 00/18] introduce a new tool, valid access checker js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 01/18] mm/kasan: make some kasan functions global js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 02/18] vchecker: introduce the valid access checker js1304 2017-11-28 7:48 ` js1304 2017-11-28 19:41 ` Andi Kleen 2017-11-28 19:41 ` Andi Kleen 2017-11-29 5:36 ` Joonsoo Kim 2017-11-29 5:36 ` Joonsoo Kim 2017-12-01 5:08 ` kbuild test robot 2017-12-01 8:01 ` Joonsoo Kim 2017-12-01 8:01 ` Joonsoo Kim 2017-11-28 7:48 ` [PATCH 03/18] vchecker: mark/unmark the shadow of the allocated objects js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` js1304 [this message] 2017-11-28 7:48 ` [PATCH 04/18] vchecker: prepare per object memory for vchecker js1304 2017-11-28 7:48 ` [PATCH 05/18] vchecker: store/report callstack of value writer js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 06/18] lib/stackdepot: Add is_new arg to depot_save_stack js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 07/18] lib/stackdepot: extend stackdepot API to support per-user stackdepot js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 08/18] vchecker: Add 'callstack' checker js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 09/18] vchecker: Support toggle on/off of callstack check js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 10/18] vchecker: Use __GFP_ATOMIC to save stacktrace js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 11/18] vchecker: consistently exclude vchecker's stacktrace js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 12/18] vchecker: fix 'remove' handling on callstack checker js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 13/18] mm/vchecker: support inline KASAN build js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 14/18] mm/vchecker: make callstack depth configurable js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 15/18] mm/vchecker: pass allocation caller address to vchecker hook js1304 2017-11-28 7:48 ` js1304 2017-12-01 2:39 ` kbuild test robot 2017-12-01 3:01 ` kbuild test robot 2017-11-28 7:48 ` [PATCH 16/18] mm/vchecker: support allocation caller filter js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 17/18] lib/vchecker_test: introduce a sample for vchecker test js1304 2017-11-28 7:48 ` js1304 2017-11-28 7:48 ` [PATCH 18/18] doc: add vchecker document js1304 2017-11-28 7:48 ` js1304 2017-11-29 9:27 ` [PATCH 00/18] introduce a new tool, valid access checker Dmitry Vyukov 2017-11-29 9:27 ` Dmitry Vyukov 2017-12-01 7:46 ` Joonsoo Kim 2017-12-01 7:46 ` Joonsoo Kim 2017-12-22 1:51 ` Joonsoo Kim 2017-12-22 1:51 ` Joonsoo Kim 2018-01-18 22:39 ` Andrew Morton 2018-01-18 22:39 ` Andrew Morton
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1511855333-3570-5-git-send-email-iamjoonsoo.kim@lge.com \ --to=js1304@gmail.com \ --cc=akpm@linux-foundation.org \ --cc=aryabinin@virtuozzo.com \ --cc=dvyukov@google.com \ --cc=glider@google.com \ --cc=iamjoonsoo.kim@lge.com \ --cc=kasan-dev@googlegroups.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=namhyung@kernel.org \ --cc=wen.gang.wang@oracle.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.