Skip to content

Commit 90db9db

Browse files
melverakpm00
authored andcommitted
kasan, powerpc: don't rename memintrinsics if compiler adds prefixes
With appropriate compiler support [1], KASAN builds use __asan prefixed meminstrinsics, and KASAN no longer overrides memcpy/memset/memmove. If compiler support is detected (CC_HAS_KASAN_MEMINTRINSIC_PREFIX), define memintrinsics normally (do not prefix '__'). On powerpc, KASAN is the only user of __mem functions, which are used to define instrumented memintrinsics. Alias the normal versions for KASAN to use in its implementation. Link: https://lore.kernel.org/all/20230224085942.1791837-1-elver@google.com/ [1] Link: https://lore.kernel.org/oe-kbuild-all/202302271348.U5lvmo0S-lkp@intel.com/ Link: https://lkml.kernel.org/r/20230227094726.3833247-1-elver@google.com Signed-off-by: Marco Elver <elver@google.com> Reported-by: kernel test robot <lkp@intel.com> Acked-by: Michael Ellerman <mpe@ellerman.id.au> [powerpc] Cc: Alexander Potapenko <glider@google.com> Cc: Andrey Konovalov <andreyknvl@gmail.com> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Daniel Axtens <dja@axtens.net> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Liam R. Howlett <Liam.Howlett@oracle.com> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 6db504c commit 90db9db

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

arch/powerpc/include/asm/kasan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef __ASM_KASAN_H
33
#define __ASM_KASAN_H
44

5-
#ifdef CONFIG_KASAN
5+
#if defined(CONFIG_KASAN) && !defined(CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX)
66
#define _GLOBAL_KASAN(fn) _GLOBAL(__##fn)
77
#define _GLOBAL_TOC_KASAN(fn) _GLOBAL_TOC(__##fn)
88
#define EXPORT_SYMBOL_KASAN(fn) EXPORT_SYMBOL(__##fn)

arch/powerpc/include/asm/string.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ extern int memcmp(const void *,const void *,__kernel_size_t);
3030
extern void * memchr(const void *,int,__kernel_size_t);
3131
void memcpy_flushcache(void *dest, const void *src, size_t size);
3232

33+
#ifdef CONFIG_KASAN
34+
/* __mem variants are used by KASAN to implement instrumented meminstrinsics. */
35+
#ifdef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
36+
#define __memset memset
37+
#define __memcpy memcpy
38+
#define __memmove memmove
39+
#else /* CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */
3340
void *__memset(void *s, int c, __kernel_size_t count);
3441
void *__memcpy(void *to, const void *from, __kernel_size_t n);
3542
void *__memmove(void *to, const void *from, __kernel_size_t n);
36-
37-
#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
43+
#ifndef __SANITIZE_ADDRESS__
3844
/*
3945
* For files that are not instrumented (e.g. mm/slub.c) we
4046
* should use not instrumented version of mem* functions.
@@ -46,8 +52,9 @@ void *__memmove(void *to, const void *from, __kernel_size_t n);
4652
#ifndef __NO_FORTIFY
4753
#define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */
4854
#endif
49-
50-
#endif
55+
#endif /* !__SANITIZE_ADDRESS__ */
56+
#endif /* CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */
57+
#endif /* CONFIG_KASAN */
5158

5259
#ifdef CONFIG_PPC64
5360
#ifndef CONFIG_KASAN

arch/powerpc/kernel/prom_init_check.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@
1313
# If you really need to reference something from prom_init.o add
1414
# it to the list below:
1515

16-
grep "^CONFIG_KASAN=y$" ${KCONFIG_CONFIG} >/dev/null
17-
if [ $? -eq 0 ]
16+
has_renamed_memintrinsics()
17+
{
18+
grep -q "^CONFIG_KASAN=y$" ${KCONFIG_CONFIG} && \
19+
! grep -q "^CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX=y" ${KCONFIG_CONFIG}
20+
}
21+
22+
if has_renamed_memintrinsics
1823
then
1924
MEM_FUNCS="__memcpy __memset"
2025
else

0 commit comments

Comments
 (0)