The patch titled Subject: mm/kasan: change kasan_check_{read,write} to return boolean has been added to the -mm tree. Its filename is mm-kasan-change-kasan_check_readwrite-to-return-boolean.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-kasan-change-kasan_check_readwrite-to-return-boolean.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-kasan-change-kasan_check_readwrite-to-return-boolean.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: Marco Elver <elver@xxxxxxxxxx> Subject: mm/kasan: change kasan_check_{read,write} to return boolean This changes {,__}kasan_check_{read,write} functions to return a boolean denoting if the access was valid or not. Link: http://lkml.kernel.org/r/20190626142014.141844-3-elver@xxxxxxxxxx Signed-off-by: Marco Elver <elver@xxxxxxxxxx> Cc: Andrey Ryabinin <aryabinin@xxxxxxxxxxxxx> Cc: Dmitry Vyukov <dvyukov@xxxxxxxxxx> Cc: Alexander Potapenko <glider@xxxxxxxxxx> Cc: Andrey Konovalov <andreyknvl@xxxxxxxxxx> Cc: Christoph Lameter <cl@xxxxxxxxx> Cc: Pekka Enberg <penberg@xxxxxxxxxx> Cc: David Rientjes <rientjes@xxxxxxxxxx> Cc: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx> Cc: Mark Rutland <mark.rutland@xxxxxxx> Cc: Kees Cook <keescook@xxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/kasan-checks.h | 36 ++++++++++++++++++++------------- mm/kasan/common.c | 8 +++---- mm/kasan/generic.c | 13 ++++++----- mm/kasan/kasan.h | 10 ++++++++- mm/kasan/tags.c | 12 ++++++----- 5 files changed, 49 insertions(+), 30 deletions(-) --- a/include/linux/kasan-checks.h~mm-kasan-change-kasan_check_readwrite-to-return-boolean +++ a/include/linux/kasan-checks.h @@ -8,13 +8,17 @@ * to validate access to an address. Never use these in header files! */ #ifdef CONFIG_KASAN -void __kasan_check_read(const volatile void *p, unsigned int size); -void __kasan_check_write(const volatile void *p, unsigned int size); +bool __kasan_check_read(const volatile void *p, unsigned int size); +bool __kasan_check_write(const volatile void *p, unsigned int size); #else -static inline void __kasan_check_read(const volatile void *p, unsigned int size) -{ } -static inline void __kasan_check_write(const volatile void *p, unsigned int size) -{ } +static inline bool __kasan_check_read(const volatile void *p, unsigned int size) +{ + return true; +} +static inline bool __kasan_check_write(const volatile void *p, unsigned int size) +{ + return true; +} #endif /* @@ -22,19 +26,23 @@ static inline void __kasan_check_write(c * instrumentation enabled. May be used in header files. */ #ifdef __SANITIZE_ADDRESS__ -static inline void kasan_check_read(const volatile void *p, unsigned int size) +static inline bool kasan_check_read(const volatile void *p, unsigned int size) { - __kasan_check_read(p, size); + return __kasan_check_read(p, size); } -static inline void kasan_check_write(const volatile void *p, unsigned int size) +static inline bool kasan_check_write(const volatile void *p, unsigned int size) { - __kasan_check_read(p, size); + return __kasan_check_read(p, size); } #else -static inline void kasan_check_read(const volatile void *p, unsigned int size) -{ } -static inline void kasan_check_write(const volatile void *p, unsigned int size) -{ } +static inline bool kasan_check_read(const volatile void *p, unsigned int size) +{ + return true; +} +static inline bool kasan_check_write(const volatile void *p, unsigned int size) +{ + return true; +} #endif #endif --- a/mm/kasan/common.c~mm-kasan-change-kasan_check_readwrite-to-return-boolean +++ a/mm/kasan/common.c @@ -87,15 +87,15 @@ void kasan_disable_current(void) current->kasan_depth--; } -void __kasan_check_read(const volatile void *p, unsigned int size) +bool __kasan_check_read(const volatile void *p, unsigned int size) { - check_memory_region((unsigned long)p, size, false, _RET_IP_); + return check_memory_region((unsigned long)p, size, false, _RET_IP_); } EXPORT_SYMBOL(__kasan_check_read); -void __kasan_check_write(const volatile void *p, unsigned int size) +bool __kasan_check_write(const volatile void *p, unsigned int size) { - check_memory_region((unsigned long)p, size, true, _RET_IP_); + return check_memory_region((unsigned long)p, size, true, _RET_IP_); } EXPORT_SYMBOL(__kasan_check_write); --- a/mm/kasan/generic.c~mm-kasan-change-kasan_check_readwrite-to-return-boolean +++ a/mm/kasan/generic.c @@ -166,29 +166,30 @@ static __always_inline bool memory_is_po return memory_is_poisoned_n(addr, size); } -static __always_inline void check_memory_region_inline(unsigned long addr, +static __always_inline bool check_memory_region_inline(unsigned long addr, size_t size, bool write, unsigned long ret_ip) { if (unlikely(size == 0)) - return; + return true; if (unlikely((void *)addr < kasan_shadow_to_mem((void *)KASAN_SHADOW_START))) { kasan_report(addr, size, write, ret_ip); - return; + return false; } if (likely(!memory_is_poisoned(addr, size))) - return; + return true; kasan_report(addr, size, write, ret_ip); + return false; } -void check_memory_region(unsigned long addr, size_t size, bool write, +bool check_memory_region(unsigned long addr, size_t size, bool write, unsigned long ret_ip) { - check_memory_region_inline(addr, size, write, ret_ip); + return check_memory_region_inline(addr, size, write, ret_ip); } void kasan_cache_shrink(struct kmem_cache *cache) --- a/mm/kasan/kasan.h~mm-kasan-change-kasan_check_readwrite-to-return-boolean +++ a/mm/kasan/kasan.h @@ -128,7 +128,15 @@ static inline bool addr_has_shadow(const void kasan_poison_shadow(const void *address, size_t size, u8 value); -void check_memory_region(unsigned long addr, size_t size, bool write, +/** + * check_memory_region - Check memory region, and report if invalid access. + * @addr: the accessed address + * @size: the accessed size + * @write: true if access is a write access + * @ret_ip: return address + * @return: true if access was valid, false if invalid + */ +bool check_memory_region(unsigned long addr, size_t size, bool write, unsigned long ret_ip); void *find_first_bad_addr(void *addr, size_t size); --- a/mm/kasan/tags.c~mm-kasan-change-kasan_check_readwrite-to-return-boolean +++ a/mm/kasan/tags.c @@ -76,7 +76,7 @@ void *kasan_reset_tag(const void *addr) return reset_tag(addr); } -void check_memory_region(unsigned long addr, size_t size, bool write, +bool check_memory_region(unsigned long addr, size_t size, bool write, unsigned long ret_ip) { u8 tag; @@ -84,7 +84,7 @@ void check_memory_region(unsigned long a void *untagged_addr; if (unlikely(size == 0)) - return; + return true; tag = get_tag((const void *)addr); @@ -106,22 +106,24 @@ void check_memory_region(unsigned long a * set to KASAN_TAG_KERNEL (0xFF)). */ if (tag == KASAN_TAG_KERNEL) - return; + return true; untagged_addr = reset_tag((const void *)addr); if (unlikely(untagged_addr < kasan_shadow_to_mem((void *)KASAN_SHADOW_START))) { kasan_report(addr, size, write, ret_ip); - return; + return false; } shadow_first = kasan_mem_to_shadow(untagged_addr); shadow_last = kasan_mem_to_shadow(untagged_addr + size - 1); for (shadow = shadow_first; shadow <= shadow_last; shadow++) { if (*shadow != tag) { kasan_report(addr, size, write, ret_ip); - return; + return false; } } + + return true; } #define DEFINE_HWASAN_LOAD_STORE(size) \ _ Patches currently in -mm which might be from elver@xxxxxxxxxx are mm-kasan-print-frame-description-for-stack-bugs.patch lib-test_kasan-add-bitops-tests.patch x86-use-static_cpu_has-in-uaccess-region-to-avoid-instrumentation.patch asm-generic-x86-add-bitops-instrumentation-for-kasan.patch mm-kasan-introduce-__kasan_check_readwrite.patch mm-kasan-change-kasan_check_readwrite-to-return-boolean.patch lib-test_kasan-add-test-for-double-kzfree-detection.patch mm-slab-refactor-common-ksize-kasan-logic-into-slab_commonc.patch mm-kasan-add-object-validation-in-ksize.patch