Commit 58ff5371 authored by Samuel Holland's avatar Samuel Holland Committed by Palmer Dabbelt

riscv: Omit optimized string routines when using KASAN

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: default avatarSamuel Holland <samuel.holland@sifive.com>
Reviewed-by: default avatarAlexandre Ghiti <alexghiti@rivosinc.com>
Tested-by: default avatarAlexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20240801033725.28816-2-samuel.holland@sifive.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
parent 8400291e
...@@ -19,6 +19,7 @@ extern asmlinkage void *__memcpy(void *, const void *, size_t); ...@@ -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);
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 #define __HAVE_ARCH_STRCMP
extern asmlinkage int strcmp(const char *cs, const char *ct); extern asmlinkage int strcmp(const char *cs, const char *ct);
...@@ -27,6 +28,7 @@ extern asmlinkage __kernel_size_t strlen(const char *); ...@@ -27,6 +28,7 @@ extern asmlinkage __kernel_size_t strlen(const char *);
#define __HAVE_ARCH_STRNCMP #define __HAVE_ARCH_STRNCMP
extern asmlinkage int strncmp(const char *cs, const char *ct, size_t count); 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. */ /* For those files which don't want to check by kasan. */
#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) #if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
......
...@@ -12,9 +12,6 @@ ...@@ -12,9 +12,6 @@
EXPORT_SYMBOL(memset); EXPORT_SYMBOL(memset);
EXPORT_SYMBOL(memcpy); EXPORT_SYMBOL(memcpy);
EXPORT_SYMBOL(memmove); EXPORT_SYMBOL(memmove);
EXPORT_SYMBOL(strcmp);
EXPORT_SYMBOL(strlen);
EXPORT_SYMBOL(strncmp);
EXPORT_SYMBOL(__memset); EXPORT_SYMBOL(__memset);
EXPORT_SYMBOL(__memcpy); EXPORT_SYMBOL(__memcpy);
EXPORT_SYMBOL(__memmove); EXPORT_SYMBOL(__memmove);
...@@ -3,9 +3,11 @@ lib-y += delay.o ...@@ -3,9 +3,11 @@ lib-y += delay.o
lib-y += memcpy.o lib-y += memcpy.o
lib-y += memset.o lib-y += memset.o
lib-y += memmove.o lib-y += memmove.o
ifeq ($(CONFIG_KASAN_GENERIC)$(CONFIG_KASAN_SW_TAGS),)
lib-y += strcmp.o lib-y += strcmp.o
lib-y += strlen.o lib-y += strlen.o
lib-y += strncmp.o lib-y += strncmp.o
endif
lib-y += csum.o lib-y += csum.o
ifeq ($(CONFIG_MMU), y) ifeq ($(CONFIG_MMU), y)
lib-$(CONFIG_RISCV_ISA_V) += uaccess_vector.o lib-$(CONFIG_RISCV_ISA_V) += uaccess_vector.o
......
...@@ -120,3 +120,4 @@ strcmp_zbb: ...@@ -120,3 +120,4 @@ strcmp_zbb:
.option pop .option pop
#endif #endif
SYM_FUNC_END(strcmp) SYM_FUNC_END(strcmp)
EXPORT_SYMBOL(strcmp)
...@@ -131,3 +131,4 @@ strlen_zbb: ...@@ -131,3 +131,4 @@ strlen_zbb:
#endif #endif
SYM_FUNC_END(strlen) SYM_FUNC_END(strlen)
SYM_FUNC_ALIAS(__pi_strlen, strlen) SYM_FUNC_ALIAS(__pi_strlen, strlen)
EXPORT_SYMBOL(strlen)
...@@ -136,3 +136,4 @@ strncmp_zbb: ...@@ -136,3 +136,4 @@ strncmp_zbb:
.option pop .option pop
#endif #endif
SYM_FUNC_END(strncmp) SYM_FUNC_END(strncmp)
EXPORT_SYMBOL(strncmp)
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
purgatory-y := purgatory.o sha256.o entry.o string.o ctype.o memcpy.o memset.o 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 purgatory-y += strcmp.o strlen.o strncmp.o
endif
targets += $(purgatory-y) targets += $(purgatory-y)
PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment