Skip to content

Commit

Permalink
kasan: don't round_up too much
Browse files Browse the repository at this point in the history
For hardware tag-based mode kasan_poison_memory() already rounds up the
size. Do the same for software modes and remove round_up() from the common
code.

Link: https://lkml.kernel.org/r/47b232474f1f89dc072aeda0fa58daa6efade377.1606162397.git.andreyknvl@google.com
Link: https://linux-review.googlesource.com/id/Ib397128fac6eba874008662b4964d65352db4aa4
Signed-off-by: Andrey Konovalov <[email protected]>
Reviewed-by: Dmitry Vyukov <[email protected]>
Reviewed-by: Marco Elver <[email protected]>
Tested-by: Vincenzo Frascino <[email protected]>
Cc: Alexander Potapenko <[email protected]>
Cc: Andrey Ryabinin <[email protected]>
Cc: Branislav Rankov <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Evgenii Stepanov <[email protected]>
Cc: Kevin Brodsky <[email protected]>
Cc: Vasily Gorbik <[email protected]>
Cc: Will Deacon <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
xairy authored and torvalds committed Dec 22, 2020
1 parent eeb3160 commit d99f6a1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
8 changes: 2 additions & 6 deletions mm/kasan/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ void __kasan_unpoison_object_data(struct kmem_cache *cache, void *object)

void __kasan_poison_object_data(struct kmem_cache *cache, void *object)
{
poison_range(object,
round_up(cache->object_size, KASAN_GRANULE_SIZE),
KASAN_KMALLOC_REDZONE);
poison_range(object, cache->object_size, KASAN_KMALLOC_REDZONE);
}

/*
Expand Down Expand Up @@ -288,7 +286,6 @@ static bool ____kasan_slab_free(struct kmem_cache *cache, void *object,
{
u8 tag;
void *tagged_object;
unsigned long rounded_up_size;

tag = get_tag(object);
tagged_object = object;
Expand All @@ -309,8 +306,7 @@ static bool ____kasan_slab_free(struct kmem_cache *cache, void *object,
return true;
}

rounded_up_size = round_up(cache->object_size, KASAN_GRANULE_SIZE);
poison_range(object, rounded_up_size, KASAN_KMALLOC_FREE);
poison_range(object, cache->object_size, KASAN_KMALLOC_FREE);

if (!kasan_stack_collection_enabled())
return false;
Expand Down
1 change: 1 addition & 0 deletions mm/kasan/shadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void poison_range(const void *address, size_t size, u8 value)
* addresses to this function.
*/
address = kasan_reset_tag(address);
size = round_up(size, KASAN_GRANULE_SIZE);

shadow_start = kasan_mem_to_shadow(address);
shadow_end = kasan_mem_to_shadow(address + size);
Expand Down

0 comments on commit d99f6a1

Please sign in to comment.