590e8a082a
Currently the common definition of function_nocfi() is provided by <linux/mm.h>, and architectures are expected to provide a definition in <asm/memory.h>. Due to header dependencies, this can make it hard to use function_nocfi() in low-level headers. As function_nocfi() has no dependency on any mm code, nor on any memory definitions, it doesn't need to live in <linux/mm.h> or <asm/memory.h>. Generally, it would make more sense for it to live in <linux/compiler.h>, where an architecture can override it in <asm/compiler.h>. Move the definitions accordingly. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Kees Cook <keescook@chromium.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Sami Tolvanen <samitolvanen@google.com> Cc: Will Deacon <will@kernel.org> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20210602153701.35957-1-mark.rutland@arm.com
43 lines
1.3 KiB
C
43 lines
1.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __ASM_COMPILER_H
|
|
#define __ASM_COMPILER_H
|
|
|
|
#ifdef ARM64_ASM_ARCH
|
|
#define ARM64_ASM_PREAMBLE ".arch " ARM64_ASM_ARCH "\n"
|
|
#else
|
|
#define ARM64_ASM_PREAMBLE
|
|
#endif
|
|
|
|
/*
|
|
* The EL0/EL1 pointer bits used by a pointer authentication code.
|
|
* This is dependent on TBI0/TBI1 being enabled, or bits 63:56 would also apply.
|
|
*/
|
|
#define ptrauth_user_pac_mask() GENMASK_ULL(54, vabits_actual)
|
|
#define ptrauth_kernel_pac_mask() GENMASK_ULL(63, vabits_actual)
|
|
|
|
/* Valid for EL0 TTBR0 and EL1 TTBR1 instruction pointers */
|
|
#define ptrauth_clear_pac(ptr) \
|
|
((ptr & BIT_ULL(55)) ? (ptr | ptrauth_kernel_pac_mask()) : \
|
|
(ptr & ~ptrauth_user_pac_mask()))
|
|
|
|
#define __builtin_return_address(val) \
|
|
(void *)(ptrauth_clear_pac((unsigned long)__builtin_return_address(val)))
|
|
|
|
#ifdef CONFIG_CFI_CLANG
|
|
/*
|
|
* With CONFIG_CFI_CLANG, the compiler replaces function address
|
|
* references with the address of the function's CFI jump table
|
|
* entry. The function_nocfi macro always returns the address of the
|
|
* actual function instead.
|
|
*/
|
|
#define function_nocfi(x) ({ \
|
|
void *addr; \
|
|
asm("adrp %0, " __stringify(x) "\n\t" \
|
|
"add %0, %0, :lo12:" __stringify(x) \
|
|
: "=r" (addr)); \
|
|
addr; \
|
|
})
|
|
#endif
|
|
|
|
#endif /* __ASM_COMPILER_H */
|