Skip to content

Commit

Permalink
mm/kasan: get rid of ->alloc_size in struct kasan_alloc_meta
Browse files Browse the repository at this point in the history
Size of slab object already stored in cache->object_size.

Note, that kmalloc() internally rounds up size of allocation, so
object_size may be not equal to alloc_size, but, usually we don't need
to know the exact size of allocated object.  In case if we need that
information, we still can figure it out from the report.  The dump of
shadow memory allows to identify the end of allocated memory, and
thereby the exact allocation size.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Andrey Ryabinin <[email protected]>
Cc: Alexander Potapenko <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
aryabinin authored and torvalds committed Aug 2, 2016
1 parent f7376ae commit 47b5c2a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
1 change: 0 additions & 1 deletion mm/kasan/kasan.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,6 @@ void kasan_kmalloc(struct kmem_cache *cache, const void *object, size_t size,
get_alloc_info(cache, object);

alloc_info->state = KASAN_STATE_ALLOC;
alloc_info->alloc_size = size;
set_track(&alloc_info->track, flags);
}
}
Expand Down
3 changes: 1 addition & 2 deletions mm/kasan/kasan.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ struct kasan_track {

struct kasan_alloc_meta {
struct kasan_track track;
u32 state : 2; /* enum kasan_state */
u32 alloc_size : 30;
u32 state;
};

struct qlist_node {
Expand Down
8 changes: 3 additions & 5 deletions mm/kasan/report.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,21 @@ static void kasan_object_err(struct kmem_cache *cache, struct page *page,
struct kasan_free_meta *free_info;

dump_stack();
pr_err("Object at %p, in cache %s\n", object, cache->name);
pr_err("Object at %p, in cache %s size: %d\n", object, cache->name,
cache->object_size);

if (!(cache->flags & SLAB_KASAN))
return;
switch (alloc_info->state) {
case KASAN_STATE_INIT:
pr_err("Object not allocated yet\n");
break;
case KASAN_STATE_ALLOC:
pr_err("Object allocated with size %u bytes.\n",
alloc_info->alloc_size);
pr_err("Allocation:\n");
print_track(&alloc_info->track);
break;
case KASAN_STATE_FREE:
case KASAN_STATE_QUARANTINE:
pr_err("Object freed, allocated with size %u bytes\n",
alloc_info->alloc_size);
free_info = get_free_info(cache, object);
pr_err("Allocation:\n");
print_track(&alloc_info->track);
Expand Down

0 comments on commit 47b5c2a

Please sign in to comment.