Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions arch/powerpc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ config CC_HAS_ELFV2
config CC_HAS_PREFIXED
def_bool PPC64 && $(cc-option, -mcpu=power10 -mprefixed)

config PPC_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
def_bool (CC_IS_CLANG && $(cc-option,-fsanitize=kernel-address -mllvm -asan-kernel-mem-intrinsic-prefix=1)) || \
(CC_IS_GCC && $(cc-option,-fsanitize=kernel-address --param asan-kernel-mem-intrinsic-prefix=1))

config CC_HAS_PCREL
# Clang has a bug (https://github.com/llvm/llvm-project/issues/62372)
# where pcrel code is not generated if -msoft-float, -mno-altivec, or
Expand Down Expand Up @@ -220,9 +224,9 @@ config PPC
select HAVE_ARCH_HUGE_VMAP if PPC_RADIX_MMU || PPC_8xx
select HAVE_ARCH_JUMP_LABEL
select HAVE_ARCH_JUMP_LABEL_RELATIVE
select HAVE_ARCH_KASAN if PPC32 && PAGE_SHIFT <= 14
select HAVE_ARCH_KASAN if PPC_RADIX_MMU
select HAVE_ARCH_KASAN if PPC_BOOK3E_64
select HAVE_ARCH_KASAN if PPC32 && PAGE_SHIFT <= 14 && PPC_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
select HAVE_ARCH_KASAN if PPC_RADIX_MMU && PPC_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
select HAVE_ARCH_KASAN if PPC_BOOK3E_64 && PPC_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
select HAVE_ARCH_KASAN_VMALLOC if HAVE_ARCH_KASAN
select HAVE_ARCH_KCSAN
select HAVE_ARCH_KFENCE if ARCH_SUPPORTS_DEBUG_PAGEALLOC
Expand Down
11 changes: 0 additions & 11 deletions arch/powerpc/include/asm/kasan.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,9 @@
#ifndef __ASM_KASAN_H
#define __ASM_KASAN_H

#if defined(CONFIG_KASAN) && !defined(CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX)
#define _GLOBAL_KASAN(fn) \
_GLOBAL(fn); \
_GLOBAL(__##fn)
#define _GLOBAL_TOC_KASAN(fn) \
_GLOBAL_TOC(fn); \
_GLOBAL_TOC(__##fn)
#define EXPORT_SYMBOL_KASAN(fn) \
EXPORT_SYMBOL(__##fn)
#else /* CONFIG_KASAN && !CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */
#define _GLOBAL_KASAN(fn) _GLOBAL(fn)
#define _GLOBAL_TOC_KASAN(fn) _GLOBAL_TOC(fn)
#define EXPORT_SYMBOL_KASAN(fn)
#endif /* CONFIG_KASAN && !CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */

#ifndef __ASSEMBLER__

Expand Down
21 changes: 1 addition & 20 deletions arch/powerpc/include/asm/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,10 @@ extern void * memchr(const void *,int,__kernel_size_t);
void memcpy_flushcache(void *dest, const void *src, size_t size);

#ifdef CONFIG_KASAN
/* __mem variants are used by KASAN to implement instrumented meminstrinsics. */
#ifdef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
/* Used by mm/kasan/shadow.c as raw backends to bypass KASAN checking. */
#define __memset memset
#define __memcpy memcpy
#define __memmove memmove
#else /* CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */
void *__memset(void *s, int c, __kernel_size_t count);
void *__memcpy(void *to, const void *from, __kernel_size_t n);
void *__memmove(void *to, const void *from, __kernel_size_t n);
#ifndef __SANITIZE_ADDRESS__
/*
* For files that are not instrumented (e.g. mm/slub.c) we
* should use not instrumented version of mem* functions.
*/
#define memcpy(dst, src, len) __memcpy(dst, src, len)
#define memmove(dst, src, len) __memmove(dst, src, len)
#define memset(s, c, n) __memset(s, c, n)

#ifndef __NO_FORTIFY
#define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */
#endif
#endif /* !__SANITIZE_ADDRESS__ */
#endif /* CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */
#endif /* CONFIG_KASAN */

#ifdef CONFIG_PPC64
Expand Down
14 changes: 11 additions & 3 deletions arch/powerpc/kernel/cputable.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ void __init set_cur_cpu_spec(struct cpu_spec *s)

t = PTRRELOC(t);
/*
* use memcpy() instead of *t = *s so that GCC replaces it
* by __memcpy() when KASAN is active
* Use memcpy() instead of *t = *s because t is a PTRRELOC-adjusted
* pointer and this code runs before the MMU mapping is established.
* A struct assignment is a compiler-generated aggregate copy whose
* implementation is not under our control in relocation-sensitive code;
* memcpy() ensures the adjusted pointer is explicitly passed to the
* copy routine.
*/
memcpy(t, s, sizeof(*t));

Expand All @@ -55,7 +59,11 @@ static struct cpu_spec * __init setup_cpu_spec(unsigned long offset,

/*
* Copy everything, then do fixups. Use memcpy() instead of *t = *s
* so that GCC replaces it by __memcpy() when KASAN is active
* because t is a PTRRELOC-adjusted pointer and this code runs before
* the MMU mapping is established. A struct assignment is a
* compiler-generated aggregate copy whose implementation is not under
* our control in relocation-sensitive code; memcpy() ensures the
* adjusted pointer is explicitly passed to the copy routine.
*/
memcpy(t, s, sizeof(*t));

Expand Down
10 changes: 6 additions & 4 deletions arch/powerpc/kernel/prom_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1363,10 +1363,12 @@ static void __init prom_check_platform_support(void)
"ibm,arch-vec-5-platform-support");

/*
* First copy the architecture vec template
*
* use memcpy() instead of *vec = *vec_template so that GCC replaces it
* by __memcpy() when KASAN is active
* First copy the architecture vec template. Use memcpy() instead of
* a struct assignment because this code runs before the MMU mapping
* is established. A struct assignment is a compiler-generated
* aggregate copy whose implementation is not under our control in
* relocation-sensitive code; memcpy() ensures the adjusted pointer
* is explicitly passed to the copy routine.
*/
memcpy(&ibm_architecture_vec, &ibm_architecture_vec_template,
sizeof(ibm_architecture_vec));
Expand Down
Loading