Skip to content

Commit 58ff537

Browse files
SiFiveHollandpalmer-dabbelt
authored andcommitted
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: Samuel Holland <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Tested-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 8400291 commit 58ff537

File tree

7 files changed

+9
-3
lines changed

7 files changed

+9
-3
lines changed

arch/riscv/include/asm/string.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern asmlinkage void *__memcpy(void *, const void *, size_t);
1919
extern asmlinkage void *memmove(void *, const void *, size_t);
2020
extern asmlinkage void *__memmove(void *, const void *, size_t);
2121

22+
#if !(defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS))
2223
#define __HAVE_ARCH_STRCMP
2324
extern asmlinkage int strcmp(const char *cs, const char *ct);
2425

@@ -27,6 +28,7 @@ extern asmlinkage __kernel_size_t strlen(const char *);
2728

2829
#define __HAVE_ARCH_STRNCMP
2930
extern asmlinkage int strncmp(const char *cs, const char *ct, size_t count);
31+
#endif
3032

3133
/* For those files which don't want to check by kasan. */
3234
#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)

arch/riscv/kernel/riscv_ksyms.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
EXPORT_SYMBOL(memset);
1313
EXPORT_SYMBOL(memcpy);
1414
EXPORT_SYMBOL(memmove);
15-
EXPORT_SYMBOL(strcmp);
16-
EXPORT_SYMBOL(strlen);
17-
EXPORT_SYMBOL(strncmp);
1815
EXPORT_SYMBOL(__memset);
1916
EXPORT_SYMBOL(__memcpy);
2017
EXPORT_SYMBOL(__memmove);

arch/riscv/lib/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ lib-y += delay.o
33
lib-y += memcpy.o
44
lib-y += memset.o
55
lib-y += memmove.o
6+
ifeq ($(CONFIG_KASAN_GENERIC)$(CONFIG_KASAN_SW_TAGS),)
67
lib-y += strcmp.o
78
lib-y += strlen.o
89
lib-y += strncmp.o
10+
endif
911
lib-y += csum.o
1012
ifeq ($(CONFIG_MMU), y)
1113
lib-$(CONFIG_RISCV_ISA_V) += uaccess_vector.o

arch/riscv/lib/strcmp.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,4 @@ strcmp_zbb:
120120
.option pop
121121
#endif
122122
SYM_FUNC_END(strcmp)
123+
EXPORT_SYMBOL(strcmp)

arch/riscv/lib/strlen.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,4 @@ strlen_zbb:
131131
#endif
132132
SYM_FUNC_END(strlen)
133133
SYM_FUNC_ALIAS(__pi_strlen, strlen)
134+
EXPORT_SYMBOL(strlen)

arch/riscv/lib/strncmp.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,4 @@ strncmp_zbb:
136136
.option pop
137137
#endif
138138
SYM_FUNC_END(strncmp)
139+
EXPORT_SYMBOL(strncmp)

arch/riscv/purgatory/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# SPDX-License-Identifier: GPL-2.0
22

33
purgatory-y := purgatory.o sha256.o entry.o string.o ctype.o memcpy.o memset.o
4+
ifeq ($(CONFIG_KASAN_GENERIC)$(CONFIG_KASAN_SW_TAGS),)
45
purgatory-y += strcmp.o strlen.o strncmp.o
6+
endif
57

68
targets += $(purgatory-y)
79
PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))

0 commit comments

Comments
 (0)