cfi.h (1352B)
1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * Clang Control Flow Integrity (CFI) support. 4 * 5 * Copyright (C) 2021 Google LLC 6 */ 7#ifndef _LINUX_CFI_H 8#define _LINUX_CFI_H 9 10#ifdef CONFIG_CFI_CLANG 11typedef void (*cfi_check_fn)(uint64_t id, void *ptr, void *diag); 12 13/* Compiler-generated function in each module, and the kernel */ 14extern void __cfi_check(uint64_t id, void *ptr, void *diag); 15 16/* 17 * Force the compiler to generate a CFI jump table entry for a function 18 * and store the jump table address to __cfi_jt_<function>. 19 */ 20#define __CFI_ADDRESSABLE(fn, __attr) \ 21 const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn 22 23#ifdef CONFIG_CFI_CLANG_SHADOW 24 25extern void cfi_module_add(struct module *mod, unsigned long base_addr); 26extern void cfi_module_remove(struct module *mod, unsigned long base_addr); 27 28#else 29 30static inline void cfi_module_add(struct module *mod, unsigned long base_addr) {} 31static inline void cfi_module_remove(struct module *mod, unsigned long base_addr) {} 32 33#endif /* CONFIG_CFI_CLANG_SHADOW */ 34 35#else /* !CONFIG_CFI_CLANG */ 36 37#ifdef CONFIG_X86_KERNEL_IBT 38 39#define __CFI_ADDRESSABLE(fn, __attr) \ 40 const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn 41 42#endif /* CONFIG_X86_KERNEL_IBT */ 43 44#endif /* CONFIG_CFI_CLANG */ 45 46#ifndef __CFI_ADDRESSABLE 47#define __CFI_ADDRESSABLE(fn, __attr) 48#endif 49 50#endif /* _LINUX_CFI_H */