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 #include <linux/stringify.h>
11
12 #ifdef CONFIG_CFI_CLANG
13 #ifdef CONFIG_MODULES
14
15 typedef void (*cfi_check_fn)(uint64_t id, void *ptr, void *diag);
16
17 /* Compiler-generated function in each module, and the kernel */
18 #define CFI_CHECK_FN __cfi_check
19 #define CFI_CHECK_FN_NAME __stringify(CFI_CHECK_FN)
20
21 extern void CFI_CHECK_FN(uint64_t id, void *ptr, void *diag);
22
23 #ifdef CONFIG_CFI_CLANG_SHADOW
24 extern void cfi_module_add(struct module *mod, unsigned long min_addr,
25 unsigned long max_addr);
26
27 extern void cfi_module_remove(struct module *mod, unsigned long min_addr,
28 unsigned long max_addr);
29 #else
cfi_module_add(struct module * mod,unsigned long min_addr,unsigned long max_addr)30 static inline void cfi_module_add(struct module *mod, unsigned long min_addr,
31 unsigned long max_addr)
32 {
33 }
34
cfi_module_remove(struct module * mod,unsigned long min_addr,unsigned long max_addr)35 static inline void cfi_module_remove(struct module *mod, unsigned long min_addr,
36 unsigned long max_addr)
37 {
38 }
39 #endif /* CONFIG_CFI_CLANG_SHADOW */
40
41 #endif /* CONFIG_MODULES */
42 #endif /* CONFIG_CFI_CLANG */
43
44 #endif /* _LINUX_CFI_H */
45