Skip to content

Commit

Permalink
arm64: Mitigate MTE issues with str{n}cmp()
Browse files Browse the repository at this point in the history
commit 59a68d4 upstream.

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: 758602c ("arm64: Import latest version of Cortex Strings' strcmp")
Fixes: 020b199 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
rmurphy-arm authored and gregkh committed Sep 30, 2021
1 parent 0375ec7 commit b032354
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions arch/arm64/include/asm/assembler.h
Expand Up @@ -525,6 +525,11 @@ alternative_endif
#define EXPORT_SYMBOL_NOKASAN(name) EXPORT_SYMBOL(name)
#endif

#ifdef CONFIG_KASAN_HW_TAGS
#define EXPORT_SYMBOL_NOHWKASAN(name)
#else
#define EXPORT_SYMBOL_NOHWKASAN(name) EXPORT_SYMBOL_NOKASAN(name)
#endif
/*
* Emit a 64-bit absolute little endian symbol reference in a way that
* ensures that it will be resolved at build time, even when building a
Expand Down
2 changes: 2 additions & 0 deletions arch/arm64/include/asm/string.h
Expand Up @@ -12,11 +12,13 @@ extern char *strrchr(const char *, int c);
#define __HAVE_ARCH_STRCHR
extern char *strchr(const char *, int c);

#ifndef CONFIG_KASAN_HW_TAGS
#define __HAVE_ARCH_STRCMP
extern int strcmp(const char *, const char *);

#define __HAVE_ARCH_STRNCMP
extern int strncmp(const char *, const char *, __kernel_size_t);
#endif

#define __HAVE_ARCH_STRLEN
extern __kernel_size_t strlen(const char *);
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/lib/strcmp.S
Expand Up @@ -173,4 +173,4 @@ L(done):
ret

SYM_FUNC_END_PI(strcmp)
EXPORT_SYMBOL_NOKASAN(strcmp)
EXPORT_SYMBOL_NOHWKASAN(strcmp)
2 changes: 1 addition & 1 deletion arch/arm64/lib/strncmp.S
Expand Up @@ -258,4 +258,4 @@ L(ret0):
ret

SYM_FUNC_END_PI(strncmp)
EXPORT_SYMBOL_NOKASAN(strncmp)
EXPORT_SYMBOL_NOHWKASAN(strncmp)

0 comments on commit b032354

Please sign in to comment.