mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 03:27:44 -04:00
kasan: support use-after-scope detection
Gcc revision 241896 implements use-after-scope detection. Will be available in gcc 7. Support it in KASAN. Gcc emits 2 new callbacks to poison/unpoison large stack objects when they go in/out of scope. Implement the callbacks and add a test. [[email protected]: v3] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Dmitry Vyukov <[email protected]> Acked-by: Andrey Ryabinin <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: <[email protected]> [4.0+] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
045d599a28
commit
828347f8f9
4 changed files with 52 additions and 0 deletions
|
|
@ -764,6 +764,25 @@ EXPORT_SYMBOL(__asan_storeN_noabort);
|
|||
void __asan_handle_no_return(void) {}
|
||||
EXPORT_SYMBOL(__asan_handle_no_return);
|
||||
|
||||
/* Emitted by compiler to poison large objects when they go out of scope. */
|
||||
void __asan_poison_stack_memory(const void *addr, size_t size)
|
||||
{
|
||||
/*
|
||||
* Addr is KASAN_SHADOW_SCALE_SIZE-aligned and the object is surrounded
|
||||
* by redzones, so we simply round up size to simplify logic.
|
||||
*/
|
||||
kasan_poison_shadow(addr, round_up(size, KASAN_SHADOW_SCALE_SIZE),
|
||||
KASAN_USE_AFTER_SCOPE);
|
||||
}
|
||||
EXPORT_SYMBOL(__asan_poison_stack_memory);
|
||||
|
||||
/* Emitted by compiler to unpoison large objects when they go into scope. */
|
||||
void __asan_unpoison_stack_memory(const void *addr, size_t size)
|
||||
{
|
||||
kasan_unpoison_shadow(addr, size);
|
||||
}
|
||||
EXPORT_SYMBOL(__asan_unpoison_stack_memory);
|
||||
|
||||
#ifdef CONFIG_MEMORY_HOTPLUG
|
||||
static int kasan_mem_notifier(struct notifier_block *nb,
|
||||
unsigned long action, void *data)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#define KASAN_STACK_MID 0xF2
|
||||
#define KASAN_STACK_RIGHT 0xF3
|
||||
#define KASAN_STACK_PARTIAL 0xF4
|
||||
#define KASAN_USE_AFTER_SCOPE 0xF8
|
||||
|
||||
/* Don't break randconfig/all*config builds */
|
||||
#ifndef KASAN_ABI_VERSION
|
||||
|
|
|
|||
|
|
@ -90,6 +90,9 @@ static void print_error_description(struct kasan_access_info *info)
|
|||
case KASAN_KMALLOC_FREE:
|
||||
bug_type = "use-after-free";
|
||||
break;
|
||||
case KASAN_USE_AFTER_SCOPE:
|
||||
bug_type = "use-after-scope";
|
||||
break;
|
||||
}
|
||||
|
||||
pr_err("BUG: KASAN: %s in %pS at addr %p\n",
|
||||
|
|
|
|||
Loading…
Reference in a new issue