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

arm64: Mitigate MTE issues with str{n}cmp()

As with strlen(), the patches importing the updated str{n}cmp()
implementations were originally developed and tested before the
advent of CONFIG_KASAN_HW_TAGS, and have subsequently revealed
not to be MTE-safe. Since in-kernel MTE is still a rather niche
case, let it temporarily fall back to the generic C versions for
correctness until we can figure out the best fix.

Fixes: 758602c04409 ("arm64: Import latest version of Cortex Strings' strcmp")
Fixes: 020b199bc70d ("arm64: Import latest version of Cortex Strings' strncmp")
Cc: <stable@vger.kernel.org> # 5.14.x
Reported-by: Branislav Rankov <branislav.rankov@arm.com>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/34dc4d12eec0adae49b0ac927df642ed10089d40.1631890770.git.robin.murphy@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

authored by

Robin Murphy and committed by
Catalin Marinas
59a68d41 8c8a3b5b

+9 -2
+5
arch/arm64/include/asm/assembler.h
··· 525 525 #define EXPORT_SYMBOL_NOKASAN(name) EXPORT_SYMBOL(name) 526 526 #endif 527 527 528 + #ifdef CONFIG_KASAN_HW_TAGS 529 + #define EXPORT_SYMBOL_NOHWKASAN(name) 530 + #else 531 + #define EXPORT_SYMBOL_NOHWKASAN(name) EXPORT_SYMBOL_NOKASAN(name) 532 + #endif 528 533 /* 529 534 * Emit a 64-bit absolute little endian symbol reference in a way that 530 535 * ensures that it will be resolved at build time, even when building a
+2
arch/arm64/include/asm/string.h
··· 12 12 #define __HAVE_ARCH_STRCHR 13 13 extern char *strchr(const char *, int c); 14 14 15 + #ifndef CONFIG_KASAN_HW_TAGS 15 16 #define __HAVE_ARCH_STRCMP 16 17 extern int strcmp(const char *, const char *); 17 18 18 19 #define __HAVE_ARCH_STRNCMP 19 20 extern int strncmp(const char *, const char *, __kernel_size_t); 21 + #endif 20 22 21 23 #define __HAVE_ARCH_STRLEN 22 24 extern __kernel_size_t strlen(const char *);
+1 -1
arch/arm64/lib/strcmp.S
··· 173 173 ret 174 174 175 175 SYM_FUNC_END_PI(strcmp) 176 - EXPORT_SYMBOL_NOKASAN(strcmp) 176 + EXPORT_SYMBOL_NOHWKASAN(strcmp)
+1 -1
arch/arm64/lib/strncmp.S
··· 258 258 ret 259 259 260 260 SYM_FUNC_END_PI(strncmp) 261 - EXPORT_SYMBOL_NOKASAN(strncmp) 261 + EXPORT_SYMBOL_NOHWKASAN(strncmp)