1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Clang Control Flow Integrity (CFI) support. 4 * 5 * Copyright (C) 2022 Google LLC 6 */ 7 #ifndef _LINUX_CFI_H 8 #define _LINUX_CFI_H 9 10 #include <linux/bug.h> 11 #include <linux/module.h> 12 #include <asm/cfi.h> 13 14 extern bool cfi_warn; 15 16 #ifndef cfi_get_offset 17 static inline int cfi_get_offset(void) 18 { 19 return 0; 20 } 21 #endif 22 23 #ifdef CONFIG_CFI_CLANG 24 enum bug_trap_type report_cfi_failure(struct pt_regs *regs, unsigned long addr, 25 unsigned long *target, u32 type); 26 27 static inline enum bug_trap_type report_cfi_failure_noaddr(struct pt_regs *regs, 28 unsigned long addr) 29 { 30 return report_cfi_failure(regs, addr, NULL, 0); 31 } 32 #endif /* CONFIG_CFI_CLANG */ 33 34 #ifdef CONFIG_ARCH_USES_CFI_TRAPS 35 bool is_cfi_trap(unsigned long addr); 36 #else 37 static inline bool is_cfi_trap(unsigned long addr) { return false; } 38 #endif 39 40 #ifdef CONFIG_MODULES 41 #ifdef CONFIG_ARCH_USES_CFI_TRAPS 42 void module_cfi_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, 43 struct module *mod); 44 #else 45 static inline void module_cfi_finalize(const Elf_Ehdr *hdr, 46 const Elf_Shdr *sechdrs, 47 struct module *mod) {} 48 #endif /* CONFIG_ARCH_USES_CFI_TRAPS */ 49 #endif /* CONFIG_MODULES */ 50 51 #ifndef CFI_NOSEAL 52 #define CFI_NOSEAL(x) 53 #endif 54 55 #endif /* _LINUX_CFI_H */ 56