Skip to content

Commit 00b400f

Browse files
author
Fox Snowpatch
committed
1 parent 5287fd8 commit 00b400f

5 files changed

Lines changed: 25 additions & 39 deletions

File tree

‎arch/powerpc/Kconfig‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ config CC_HAS_ELFV2
77
config CC_HAS_PREFIXED
88
def_bool PPC64 && $(cc-option, -mcpu=power10 -mprefixed)
99

10+
config PPC_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
11+
def_bool (CC_IS_CLANG && $(cc-option,-fsanitize=kernel-address -mllvm -asan-kernel-mem-intrinsic-prefix=1)) || \
12+
(CC_IS_GCC && $(cc-option,-fsanitize=kernel-address --param asan-kernel-mem-intrinsic-prefix=1))
13+
1014
config CC_HAS_PCREL
1115
# Clang has a bug (https://github.com/llvm/llvm-project/issues/62372)
1216
# where pcrel code is not generated if -msoft-float, -mno-altivec, or
@@ -220,9 +224,9 @@ config PPC
220224
select HAVE_ARCH_HUGE_VMAP if PPC_RADIX_MMU || PPC_8xx
221225
select HAVE_ARCH_JUMP_LABEL
222226
select HAVE_ARCH_JUMP_LABEL_RELATIVE
223-
select HAVE_ARCH_KASAN if PPC32 && PAGE_SHIFT <= 14
224-
select HAVE_ARCH_KASAN if PPC_RADIX_MMU
225-
select HAVE_ARCH_KASAN if PPC_BOOK3E_64
227+
select HAVE_ARCH_KASAN if PPC32 && PAGE_SHIFT <= 14 && PPC_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
228+
select HAVE_ARCH_KASAN if PPC_RADIX_MMU && PPC_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
229+
select HAVE_ARCH_KASAN if PPC_BOOK3E_64 && PPC_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
226230
select HAVE_ARCH_KASAN_VMALLOC if HAVE_ARCH_KASAN
227231
select HAVE_ARCH_KCSAN
228232
select HAVE_ARCH_KFENCE if ARCH_SUPPORTS_DEBUG_PAGEALLOC

‎arch/powerpc/include/asm/kasan.h‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22
#ifndef __ASM_KASAN_H
33
#define __ASM_KASAN_H
44

5-
#if defined(CONFIG_KASAN) && !defined(CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX)
6-
#define _GLOBAL_KASAN(fn) \
7-
_GLOBAL(fn); \
8-
_GLOBAL(__##fn)
9-
#define _GLOBAL_TOC_KASAN(fn) \
10-
_GLOBAL_TOC(fn); \
11-
_GLOBAL_TOC(__##fn)
12-
#define EXPORT_SYMBOL_KASAN(fn) \
13-
EXPORT_SYMBOL(__##fn)
14-
#else /* CONFIG_KASAN && !CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */
5+
/*
6+
* powerpc requires CC_HAS_KASAN_MEMINTRINSIC_PREFIX whenever KASAN is
7+
* enabled (see PPC_CC_HAS_KASAN_MEMINTRINSIC_PREFIX in arch/powerpc/Kconfig),
8+
* so the compiler always emits __asan_mem*() at instrumented call sites and
9+
* bare mem*() inside __no_sanitize_address / noinstr code. The old dual
10+
* entry-point trick (_GLOBAL_KASAN emitting both memset and __memset) is
11+
* therefore never needed.
12+
*/
1513
#define _GLOBAL_KASAN(fn) _GLOBAL(fn)
1614
#define _GLOBAL_TOC_KASAN(fn) _GLOBAL_TOC(fn)
1715
#define EXPORT_SYMBOL_KASAN(fn)
18-
#endif /* CONFIG_KASAN && !CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */
1916

2017
#ifndef __ASSEMBLER__
2118

‎arch/powerpc/include/asm/string.h‎

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,14 @@ extern void * memchr(const void *,int,__kernel_size_t);
2929
void memcpy_flushcache(void *dest, const void *src, size_t size);
3030

3131
#ifdef CONFIG_KASAN
32-
/* __mem variants are used by KASAN to implement instrumented meminstrinsics. */
33-
#ifdef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
32+
/*
33+
* powerpc requires CC_HAS_KASAN_MEMINTRINSIC_PREFIX whenever KASAN is
34+
* enabled, so the compiler emits __asan_mem*() at instrumented sites.
35+
* The raw mem* symbols are always safe to call directly.
36+
*/
3437
#define __memset memset
3538
#define __memcpy memcpy
3639
#define __memmove memmove
37-
#else /* CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */
38-
void *__memset(void *s, int c, __kernel_size_t count);
39-
void *__memcpy(void *to, const void *from, __kernel_size_t n);
40-
void *__memmove(void *to, const void *from, __kernel_size_t n);
41-
#ifndef __SANITIZE_ADDRESS__
42-
/*
43-
* For files that are not instrumented (e.g. mm/slub.c) we
44-
* should use not instrumented version of mem* functions.
45-
*/
46-
#define memcpy(dst, src, len) __memcpy(dst, src, len)
47-
#define memmove(dst, src, len) __memmove(dst, src, len)
48-
#define memset(s, c, n) __memset(s, c, n)
49-
50-
#ifndef __NO_FORTIFY
51-
#define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */
52-
#endif
53-
#endif /* !__SANITIZE_ADDRESS__ */
54-
#endif /* CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */
5540
#endif /* CONFIG_KASAN */
5641

5742
#ifdef CONFIG_PPC64

‎arch/powerpc/kernel/cputable.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ void __init set_cur_cpu_spec(struct cpu_spec *s)
3636

3737
t = PTRRELOC(t);
3838
/*
39-
* use memcpy() instead of *t = *s so that GCC replaces it
40-
* by __memcpy() when KASAN is active
39+
* use memcpy() instead of *t = *s so that the compiler replaces it
40+
* by __asan_memcpy() when KASAN is active
4141
*/
4242
memcpy(t, s, sizeof(*t));
4343

@@ -55,7 +55,7 @@ static struct cpu_spec * __init setup_cpu_spec(unsigned long offset,
5555

5656
/*
5757
* Copy everything, then do fixups. Use memcpy() instead of *t = *s
58-
* so that GCC replaces it by __memcpy() when KASAN is active
58+
* so that the compiler replaces it by __asan_memcpy() when KASAN is active
5959
*/
6060
memcpy(t, s, sizeof(*t));
6161

‎arch/powerpc/kernel/prom_init.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,8 +1365,8 @@ static void __init prom_check_platform_support(void)
13651365
/*
13661366
* First copy the architecture vec template
13671367
*
1368-
* use memcpy() instead of *vec = *vec_template so that GCC replaces it
1369-
* by __memcpy() when KASAN is active
1368+
* use memcpy() instead of *vec = *vec_template so that the compiler
1369+
* replaces it by __asan_memcpy() when KASAN is active
13701370
*/
13711371
memcpy(&ibm_architecture_vec, &ibm_architecture_vec_template,
13721372
sizeof(ibm_architecture_vec));

0 commit comments

Comments
 (0)