The patch titled Subject: kasan: rename (un)poison_shadow to (un)poison_memory has been added to the -mm tree. Its filename is kasan-rename-unpoison_shadow-to-unpoison_memory.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/kasan-rename-unpoison_shadow-to-unpoison_memory.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/kasan-rename-unpoison_shadow-to-unpoison_memory.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Andrey Konovalov <andreyknvl@xxxxxxxxxx> Subject: kasan: rename (un)poison_shadow to (un)poison_memory This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. The new mode won't be using shadow memory, but will reuse the same functions. Rename kasan_unpoison_shadow to kasan_unpoison_memory, and kasan_poison_shadow to kasan_poison_memory. No functional changes. Link: https://lkml.kernel.org/r/f26e54bcfe216118762632ecde260a5f6c605594.1605046192.git.andreyknvl@xxxxxxxxxx Signed-off-by: Andrey Konovalov <andreyknvl@xxxxxxxxxx> Signed-off-by: Vincenzo Frascino <vincenzo.frascino@xxxxxxx> Reviewed-by: Marco Elver <elver@xxxxxxxxxx> Cc: Alexander Potapenko <glider@xxxxxxxxxx> Cc: Andrey Ryabinin <aryabinin@xxxxxxxxxxxxx> Cc: Branislav Rankov <Branislav.Rankov@xxxxxxx> Cc: Catalin Marinas <catalin.marinas@xxxxxxx> Cc: Dmitry Vyukov <dvyukov@xxxxxxxxxx> Cc: Evgenii Stepanov <eugenis@xxxxxxxxxx> Cc: Kevin Brodsky <kevin.brodsky@xxxxxxx> Cc: Vasily Gorbik <gor@xxxxxxxxxxxxx> Cc: Will Deacon <will.deacon@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/kasan.h | 6 +++--- kernel/fork.c | 4 ++-- mm/kasan/common.c | 38 +++++++++++++++++++------------------- mm/kasan/generic.c | 12 ++++++------ mm/kasan/kasan.h | 2 +- mm/kasan/tags.c | 2 +- mm/slab_common.c | 2 +- 7 files changed, 33 insertions(+), 33 deletions(-) --- a/include/linux/kasan.h~kasan-rename-unpoison_shadow-to-unpoison_memory +++ a/include/linux/kasan.h @@ -71,7 +71,7 @@ extern void kasan_enable_current(void); /* Disable reporting bugs for current task */ extern void kasan_disable_current(void); -void kasan_unpoison_shadow(const void *address, size_t size); +void kasan_unpoison_memory(const void *address, size_t size); void kasan_unpoison_task_stack(struct task_struct *task); @@ -108,7 +108,7 @@ struct kasan_cache { size_t __ksize(const void *); static inline void kasan_unpoison_slab(const void *ptr) { - kasan_unpoison_shadow(ptr, __ksize(ptr)); + kasan_unpoison_memory(ptr, __ksize(ptr)); } size_t kasan_metadata_size(struct kmem_cache *cache); @@ -117,7 +117,7 @@ void kasan_restore_multi_shot(bool enabl #else /* CONFIG_KASAN */ -static inline void kasan_unpoison_shadow(const void *address, size_t size) {} +static inline void kasan_unpoison_memory(const void *address, size_t size) {} static inline void kasan_unpoison_task_stack(struct task_struct *task) {} --- a/kernel/fork.c~kasan-rename-unpoison_shadow-to-unpoison_memory +++ a/kernel/fork.c @@ -225,8 +225,8 @@ static unsigned long *alloc_thread_stack if (!s) continue; - /* Clear the KASAN shadow of the stack. */ - kasan_unpoison_shadow(s->addr, THREAD_SIZE); + /* Mark stack accessible for KASAN. */ + kasan_unpoison_memory(s->addr, THREAD_SIZE); /* Clear stale pointers from reused stack. */ memset(s->addr, 0, THREAD_SIZE); --- a/mm/kasan/common.c~kasan-rename-unpoison_shadow-to-unpoison_memory +++ a/mm/kasan/common.c @@ -109,7 +109,7 @@ void *memcpy(void *dest, const void *src * Poisons the shadow memory for 'size' bytes starting from 'addr'. * Memory addresses should be aligned to KASAN_SHADOW_SCALE_SIZE. */ -void kasan_poison_shadow(const void *address, size_t size, u8 value) +void kasan_poison_memory(const void *address, size_t size, u8 value) { void *shadow_start, *shadow_end; @@ -130,7 +130,7 @@ void kasan_poison_shadow(const void *add __memset(shadow_start, value, shadow_end - shadow_start); } -void kasan_unpoison_shadow(const void *address, size_t size) +void kasan_unpoison_memory(const void *address, size_t size) { u8 tag = get_tag(address); @@ -149,7 +149,7 @@ void kasan_unpoison_shadow(const void *a if (is_kfence_address(address)) return; - kasan_poison_shadow(address, size, tag); + kasan_poison_memory(address, size, tag); if (size & KASAN_SHADOW_MASK) { u8 *shadow = (u8 *)kasan_mem_to_shadow(address + size); @@ -166,7 +166,7 @@ static void __kasan_unpoison_stack(struc void *base = task_stack_page(task); size_t size = sp - base; - kasan_unpoison_shadow(base, size); + kasan_unpoison_memory(base, size); } /* Unpoison the entire stack for a task. */ @@ -185,7 +185,7 @@ asmlinkage void kasan_unpoison_task_stac */ void *base = (void *)((unsigned long)watermark & ~(THREAD_SIZE - 1)); - kasan_unpoison_shadow(base, watermark - base); + kasan_unpoison_memory(base, watermark - base); } void kasan_alloc_pages(struct page *page, unsigned int order) @@ -199,13 +199,13 @@ void kasan_alloc_pages(struct page *page tag = random_tag(); for (i = 0; i < (1 << order); i++) page_kasan_tag_set(page + i, tag); - kasan_unpoison_shadow(page_address(page), PAGE_SIZE << order); + kasan_unpoison_memory(page_address(page), PAGE_SIZE << order); } void kasan_free_pages(struct page *page, unsigned int order) { if (likely(!PageHighMem(page))) - kasan_poison_shadow(page_address(page), + kasan_poison_memory(page_address(page), PAGE_SIZE << order, KASAN_FREE_PAGE); } @@ -297,18 +297,18 @@ void kasan_poison_slab(struct page *page for (i = 0; i < compound_nr(page); i++) page_kasan_tag_reset(page + i); - kasan_poison_shadow(page_address(page), page_size(page), + kasan_poison_memory(page_address(page), page_size(page), KASAN_KMALLOC_REDZONE); } void kasan_unpoison_object_data(struct kmem_cache *cache, void *object) { - kasan_unpoison_shadow(object, cache->object_size); + kasan_unpoison_memory(object, cache->object_size); } void kasan_poison_object_data(struct kmem_cache *cache, void *object) { - kasan_poison_shadow(object, + kasan_poison_memory(object, round_up(cache->object_size, KASAN_SHADOW_SCALE_SIZE), KASAN_KMALLOC_REDZONE); } @@ -424,7 +424,7 @@ static bool __kasan_slab_free(struct kme } rounded_up_size = round_up(cache->object_size, KASAN_SHADOW_SCALE_SIZE); - kasan_poison_shadow(object, rounded_up_size, KASAN_KMALLOC_FREE); + kasan_poison_memory(object, rounded_up_size, KASAN_KMALLOC_FREE); if ((IS_ENABLED(CONFIG_KASAN_GENERIC) && !quarantine) || unlikely(!(cache->flags & SLAB_KASAN))) @@ -467,8 +467,8 @@ static void *__kasan_kmalloc(struct kmem tag = assign_tag(cache, object, false, keep_tag); /* Tag is ignored in set_tag without CONFIG_KASAN_SW_TAGS */ - kasan_unpoison_shadow(set_tag(object, tag), size); - kasan_poison_shadow((void *)redzone_start, redzone_end - redzone_start, + kasan_unpoison_memory(set_tag(object, tag), size); + kasan_poison_memory((void *)redzone_start, redzone_end - redzone_start, KASAN_KMALLOC_REDZONE); if (cache->flags & SLAB_KASAN) @@ -508,8 +508,8 @@ void * __must_check kasan_kmalloc_large( KASAN_SHADOW_SCALE_SIZE); redzone_end = (unsigned long)ptr + page_size(page); - kasan_unpoison_shadow(ptr, size); - kasan_poison_shadow((void *)redzone_start, redzone_end - redzone_start, + kasan_unpoison_memory(ptr, size); + kasan_poison_memory((void *)redzone_start, redzone_end - redzone_start, KASAN_PAGE_REDZONE); return (void *)ptr; @@ -542,7 +542,7 @@ void kasan_poison_kfree(void *ptr, unsig kasan_report_invalid_free(ptr, ip); return; } - kasan_poison_shadow(ptr, page_size(page), KASAN_FREE_PAGE); + kasan_poison_memory(ptr, page_size(page), KASAN_FREE_PAGE); } else { __kasan_slab_free(page->slab_cache, ptr, ip, false); } @@ -728,7 +728,7 @@ int kasan_populate_vmalloc(unsigned long * // vmalloc() allocates memory * // let a = area->addr * // we reach kasan_populate_vmalloc - * // and call kasan_unpoison_shadow: + * // and call kasan_unpoison_memory: * STORE shadow(a), unpoison_val * ... * STORE shadow(a+99), unpoison_val x = LOAD p @@ -763,7 +763,7 @@ void kasan_poison_vmalloc(const void *st return; size = round_up(size, KASAN_SHADOW_SCALE_SIZE); - kasan_poison_shadow(start, size, KASAN_VMALLOC_INVALID); + kasan_poison_memory(start, size, KASAN_VMALLOC_INVALID); } void kasan_unpoison_vmalloc(const void *start, unsigned long size) @@ -771,7 +771,7 @@ void kasan_unpoison_vmalloc(const void * if (!is_vmalloc_or_module_addr(start)) return; - kasan_unpoison_shadow(start, size); + kasan_unpoison_memory(start, size); } static int kasan_depopulate_vmalloc_pte(pte_t *ptep, unsigned long addr, --- a/mm/kasan/generic.c~kasan-rename-unpoison_shadow-to-unpoison_memory +++ a/mm/kasan/generic.c @@ -203,9 +203,9 @@ static void register_global(struct kasan { size_t aligned_size = round_up(global->size, KASAN_SHADOW_SCALE_SIZE); - kasan_unpoison_shadow(global->beg, global->size); + kasan_unpoison_memory(global->beg, global->size); - kasan_poison_shadow(global->beg + aligned_size, + kasan_poison_memory(global->beg + aligned_size, global->size_with_redzone - aligned_size, KASAN_GLOBAL_REDZONE); } @@ -286,11 +286,11 @@ void __asan_alloca_poison(unsigned long WARN_ON(!IS_ALIGNED(addr, KASAN_ALLOCA_REDZONE_SIZE)); - kasan_unpoison_shadow((const void *)(addr + rounded_down_size), + kasan_unpoison_memory((const void *)(addr + rounded_down_size), size - rounded_down_size); - kasan_poison_shadow(left_redzone, KASAN_ALLOCA_REDZONE_SIZE, + kasan_poison_memory(left_redzone, KASAN_ALLOCA_REDZONE_SIZE, KASAN_ALLOCA_LEFT); - kasan_poison_shadow(right_redzone, + kasan_poison_memory(right_redzone, padding_size + KASAN_ALLOCA_REDZONE_SIZE, KASAN_ALLOCA_RIGHT); } @@ -302,7 +302,7 @@ void __asan_allocas_unpoison(const void if (unlikely(!stack_top || stack_top > stack_bottom)) return; - kasan_unpoison_shadow(stack_top, stack_bottom - stack_top); + kasan_unpoison_memory(stack_top, stack_bottom - stack_top); } EXPORT_SYMBOL(__asan_allocas_unpoison); --- a/mm/kasan/kasan.h~kasan-rename-unpoison_shadow-to-unpoison_memory +++ a/mm/kasan/kasan.h @@ -150,7 +150,7 @@ static inline bool addr_has_shadow(const return (addr >= kasan_shadow_to_mem((void *)KASAN_SHADOW_START)); } -void kasan_poison_shadow(const void *address, size_t size, u8 value); +void kasan_poison_memory(const void *address, size_t size, u8 value); /** * check_memory_region - Check memory region, and report if invalid access. --- a/mm/kasan/tags.c~kasan-rename-unpoison_shadow-to-unpoison_memory +++ a/mm/kasan/tags.c @@ -153,7 +153,7 @@ EXPORT_SYMBOL(__hwasan_storeN_noabort); void __hwasan_tag_memory(unsigned long addr, u8 tag, unsigned long size) { - kasan_poison_shadow((void *)addr, size, tag); + kasan_poison_memory((void *)addr, size, tag); } EXPORT_SYMBOL(__hwasan_tag_memory); --- a/mm/slab_common.c~kasan-rename-unpoison_shadow-to-unpoison_memory +++ a/mm/slab_common.c @@ -1179,7 +1179,7 @@ size_t ksize(const void *objp) * We assume that ksize callers could use whole allocated area, * so we need to unpoison this area. */ - kasan_unpoison_shadow(objp, size); + kasan_unpoison_memory(objp, size); return size; } EXPORT_SYMBOL(ksize); _ Patches currently in -mm which might be from andreyknvl@xxxxxxxxxx are kasan-drop-unnecessary-gpl-text-from-comment-headers.patch kasan-kasan_vmalloc-depends-on-kasan_generic.patch kasan-group-vmalloc-code.patch s390-kasan-include-asm-pageh-from-asm-kasanh.patch kasan-shadow-declarations-only-for-software-modes.patch kasan-rename-unpoison_shadow-to-unpoison_memory.patch kasan-rename-kasan_shadow_-to-kasan_granule_.patch kasan-only-build-initc-for-software-modes.patch kasan-split-out-shadowc-from-commonc.patch kasan-define-kasan_granule_page.patch kasan-rename-report-and-tags-files.patch kasan-dont-duplicate-config-dependencies.patch kasan-hide-invalid-free-check-implementation.patch kasan-decode-stack-frame-only-with-kasan_stack_enable.patch kasan-arm64-only-init-shadow-for-software-modes.patch kasan-arm64-only-use-kasan_depth-for-software-modes.patch kasan-arm64-move-initialization-message.patch kasan-arm64-rename-kasan_init_tags-and-mark-as-__init.patch kasan-rename-addr_has_shadow-to-addr_has_metadata.patch kasan-rename-print_shadow_for_address-to-print_memory_metadata.patch kasan-kasan_non_canonical_hook-only-for-software-modes.patch kasan-rename-shadow-layout-macros-to-meta.patch kasan-separate-metadata_fetch_row-for-each-mode.patch kasan-arm64-dont-allow-sw_tags-with-arm64_mte.patch kasan-introduce-config_kasan_hw_tags.patch arm64-kasan-align-allocations-for-hw_tags.patch arm64-kasan-add-arch-layer-for-memory-tagging-helpers.patch kasan-define-kasan_granule_size-for-hw_tags.patch kasan-x86-s390-update-undef-config_kasan.patch kasan-arm64-expand-config_kasan-checks.patch kasan-arm64-implement-hw_tags-runtime.patch kasan-arm64-print-report-from-tag-fault-handler.patch kasan-mm-reset-tags-when-accessing-metadata.patch kasan-arm64-enable-config_kasan_hw_tags.patch kasan-add-documentation-for-hardware-tag-based-mode.patch