• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Clang Control Flow Integrity (CFI) support.
4  *
5  * Copyright (C) 2019 Google LLC
6  */
7 #ifndef _LINUX_CFI_H
8 #define _LINUX_CFI_H
9 
10 #ifdef CONFIG_CFI_CLANG
11 typedef void (*cfi_check_fn)(uint64_t id, void *ptr, void *diag);
12 
13 /* Compiler-generated function in each module, and the kernel */
14 extern 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) \
21 	const void* __cfi_jt_ ## fn __visible = (void *)&fn;
22 
23 #ifdef CONFIG_CFI_CLANG_SHADOW
24 
25 extern void cfi_module_add(struct module *mod, unsigned long base_addr);
26 extern void cfi_module_remove(struct module *mod, unsigned long base_addr);
27 
28 #else
29 
cfi_module_add(struct module * mod,unsigned long base_addr)30 static inline void cfi_module_add(struct module *mod, unsigned long base_addr) {}
cfi_module_remove(struct module * mod,unsigned long base_addr)31 static 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 #define __CFI_ADDRESSABLE(fn)
38 
39 #endif /* CONFIG_CFI_CLANG */
40 
41 #endif /* _LINUX_CFI_H */
42