]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
riscv: Omit optimized string routines when using KASAN
authorSamuel Holland <samuel.holland@sifive.com>
Thu, 1 Aug 2024 03:36:59 +0000 (20:36 -0700)
committerPalmer Dabbelt <palmer@rivosinc.com>
Thu, 19 Sep 2024 08:10:00 +0000 (01:10 -0700)
The optimized string routines are implemented in assembly, so they are
not instrumented for use with KASAN. Fall back to the C version of the
routines in order to improve KASAN coverage. This fixes the
kasan_strings() unit test.

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20240801033725.28816-2-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/string.h
arch/riscv/kernel/riscv_ksyms.c
arch/riscv/lib/Makefile
arch/riscv/lib/strcmp.S
arch/riscv/lib/strlen.S
arch/riscv/lib/strncmp.S
arch/riscv/purgatory/Makefile

index a96b1fea24fe43089d1f9e5d00f8417a2213ff0f..5ba77f60bf0b5846900bc8a5e9ee080c3a29f7e4 100644 (file)
@@ -19,6 +19,7 @@ extern asmlinkage void *__memcpy(void *, const void *, size_t);
 extern asmlinkage void *memmove(void *, const void *, size_t);
 extern asmlinkage void *__memmove(void *, const void *, size_t);
 
+#if !(defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS))
 #define __HAVE_ARCH_STRCMP
 extern asmlinkage int strcmp(const char *cs, const char *ct);
 
@@ -27,6 +28,7 @@ extern asmlinkage __kernel_size_t strlen(const char *);
 
 #define __HAVE_ARCH_STRNCMP
 extern asmlinkage int strncmp(const char *cs, const char *ct, size_t count);
+#endif
 
 /* For those files which don't want to check by kasan. */
 #if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
index a72879b4249a5d54813ffb5f0204745dbd3c06ac..5ab1c7e1a6ed5dc098034e88ecbddb196bdc060f 100644 (file)
@@ -12,9 +12,6 @@
 EXPORT_SYMBOL(memset);
 EXPORT_SYMBOL(memcpy);
 EXPORT_SYMBOL(memmove);
-EXPORT_SYMBOL(strcmp);
-EXPORT_SYMBOL(strlen);
-EXPORT_SYMBOL(strncmp);
 EXPORT_SYMBOL(__memset);
 EXPORT_SYMBOL(__memcpy);
 EXPORT_SYMBOL(__memmove);
index 2b369f51b0a5ed6314ee0caa0c7b4ddab2fcf046..8eec6b69a875f89c0b60be8a96c87882764b38b0 100644 (file)
@@ -3,9 +3,11 @@ lib-y                  += delay.o
 lib-y                  += memcpy.o
 lib-y                  += memset.o
 lib-y                  += memmove.o
+ifeq ($(CONFIG_KASAN_GENERIC)$(CONFIG_KASAN_SW_TAGS),)
 lib-y                  += strcmp.o
 lib-y                  += strlen.o
 lib-y                  += strncmp.o
+endif
 lib-y                  += csum.o
 ifeq ($(CONFIG_MMU), y)
 lib-$(CONFIG_RISCV_ISA_V)      += uaccess_vector.o
index 687b2bea5c438c8157353b02eb3432d3ecec166a..542301a67a2ff7b4925a888ea6419dfe15e2f877 100644 (file)
@@ -120,3 +120,4 @@ strcmp_zbb:
 .option pop
 #endif
 SYM_FUNC_END(strcmp)
+EXPORT_SYMBOL(strcmp)
index 8ae3064e45ff00592d2b927ee8cc6e4216642867..962983b73251e312cf7413198c4e9e1acb826edf 100644 (file)
@@ -131,3 +131,4 @@ strlen_zbb:
 #endif
 SYM_FUNC_END(strlen)
 SYM_FUNC_ALIAS(__pi_strlen, strlen)
+EXPORT_SYMBOL(strlen)
index aba5b3148621d8308523affc6dee8b5d61b1f16a..0f359ea2f55b292cca7d6edf4923cba42bfa98b0 100644 (file)
@@ -136,3 +136,4 @@ strncmp_zbb:
 .option pop
 #endif
 SYM_FUNC_END(strncmp)
+EXPORT_SYMBOL(strncmp)
index f11945ee24903123cb119076228881d12618c5bf..fb9c917c9b45735d35be5166455331fddda65ef9 100644 (file)
@@ -1,7 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0
 
 purgatory-y := purgatory.o sha256.o entry.o string.o ctype.o memcpy.o memset.o
+ifeq ($(CONFIG_KASAN_GENERIC)$(CONFIG_KASAN_SW_TAGS),)
 purgatory-y += strcmp.o strlen.o strncmp.o
+endif
 
 targets += $(purgatory-y)
 PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))