The patch titled Subject: mm/kasan: introduce __kasan_check_{read,write} has been added to the -mm tree. Its filename is mm-kasan-introduce-__kasan_check_readwrite.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-kasan-introduce-__kasan_check_readwrite.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-kasan-introduce-__kasan_check_readwrite.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: introduce __kasan_check_{read,write} Patch series "mm/kasan: Add object validation in ksize()", v3. This patch (of 5): This introduces __kasan_check_{read,write}. __kasan_check functions may be used from anywhere, even compilation units that disable instrumentation selectively. This change eliminates the need for the __KASAN_INTERNAL definition. Link: http://lkml.kernel.org/r/20190626142014.141844-2-elver@xxxxxxxxxx Signed-off-by: Marco Elver <elver@xxxxxxxxxx> Acked-by: Mark Rutland <mark.rutland@xxxxxxx> 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: Kees Cook <keescook@xxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/kasan-checks.h | 31 ++++++++++++++++++++++++++++--- mm/kasan/common.c | 10 ++++------ 2 files changed, 32 insertions(+), 9 deletions(-) --- a/include/linux/kasan-checks.h~mm-kasan-introduce-__kasan_check_readwrite +++ a/include/linux/kasan-checks.h @@ -2,9 +2,34 @@ #ifndef _LINUX_KASAN_CHECKS_H #define _LINUX_KASAN_CHECKS_H -#if defined(__SANITIZE_ADDRESS__) || defined(__KASAN_INTERNAL) -void kasan_check_read(const volatile void *p, unsigned int size); -void kasan_check_write(const volatile void *p, unsigned int size); +/* + * __kasan_check_*: Always available when KASAN is enabled. This may be used + * even in compilation units that selectively disable KASAN, but must use KASAN + * 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); +#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) +{ } +#endif + +/* + * kasan_check_*: Only available when the particular compilation unit has KASAN + * instrumentation enabled. May be used in header files. + */ +#ifdef __SANITIZE_ADDRESS__ +static inline void kasan_check_read(const volatile void *p, unsigned int size) +{ + __kasan_check_read(p, size); +} +static inline void kasan_check_write(const volatile void *p, unsigned int size) +{ + __kasan_check_read(p, size); +} #else static inline void kasan_check_read(const volatile void *p, unsigned int size) { } --- a/mm/kasan/common.c~mm-kasan-introduce-__kasan_check_readwrite +++ a/mm/kasan/common.c @@ -14,8 +14,6 @@ * */ -#define __KASAN_INTERNAL - #include <linux/export.h> #include <linux/interrupt.h> #include <linux/init.h> @@ -89,17 +87,17 @@ void kasan_disable_current(void) current->kasan_depth--; } -void kasan_check_read(const volatile void *p, unsigned int size) +void __kasan_check_read(const volatile void *p, unsigned int size) { check_memory_region((unsigned long)p, size, false, _RET_IP_); } -EXPORT_SYMBOL(kasan_check_read); +EXPORT_SYMBOL(__kasan_check_read); -void kasan_check_write(const volatile void *p, unsigned int size) +void __kasan_check_write(const volatile void *p, unsigned int size) { check_memory_region((unsigned long)p, size, true, _RET_IP_); } -EXPORT_SYMBOL(kasan_check_write); +EXPORT_SYMBOL(__kasan_check_write); #undef memset void *memset(void *addr, int c, size_t len) _ 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