Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/kasan: provide uninstrumented __strlen

s390 kasan code uses sclp_early_printk to report initialization
failures. The code doing that should not be instrumented, because kasan
shadow memory has not been set up yet. Even though sclp_early_core.c is
compiled with instrumentation disabled it uses strlen function, which
is instrumented and would produce shadow memory access if used. To
avoid that, introduce uninstrumented __strlen function to be used
instead.

Before commit 7e0d92f00246 ("s390/kasan: improve string/memory functions
checks") few string functions (including strlen) were escaping kasan
instrumentation due to usage of platform specific versions which are
implemented in inline assembly.

Fixes: 7e0d92f00246 ("s390/kasan: improve string/memory functions checks")
Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>

+7 -2
+7 -2
arch/s390/include/asm/string.h
··· 71 71 #define memcpy(dst, src, len) __memcpy(dst, src, len) 72 72 #define memmove(dst, src, len) __memmove(dst, src, len) 73 73 #define memset(s, c, n) __memset(s, c, n) 74 + #define strlen(s) __strlen(s) 75 + 76 + #define __no_sanitize_prefix_strfunc(x) __##x 74 77 75 78 #ifndef __NO_FORTIFY 76 79 #define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */ 77 80 #endif 78 81 82 + #else 83 + #define __no_sanitize_prefix_strfunc(x) x 79 84 #endif /* defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) */ 80 85 81 86 void *__memset16(uint16_t *s, uint16_t v, size_t count); ··· 168 163 } 169 164 #endif 170 165 171 - #ifdef __HAVE_ARCH_STRLEN 172 - static inline size_t strlen(const char *s) 166 + #if defined(__HAVE_ARCH_STRLEN) || (defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)) 167 + static inline size_t __no_sanitize_prefix_strfunc(strlen)(const char *s) 173 168 { 174 169 register unsigned long r0 asm("0") = 0; 175 170 const char *tmp = s;