hc
2024-01-31 f9004dbfff8a3fbbd7e2a88c8a4327c7f2f8e5b2
kernel/include/linux/cfi.h
....@@ -1,38 +1,41 @@
1
+/* SPDX-License-Identifier: GPL-2.0 */
2
+/*
3
+ * Clang Control Flow Integrity (CFI) support.
4
+ *
5
+ * Copyright (C) 2019 Google LLC
6
+ */
17 #ifndef _LINUX_CFI_H
28 #define _LINUX_CFI_H
39
4
-#include <linux/stringify.h>
5
-
610 #ifdef CONFIG_CFI_CLANG
7
-#ifdef CONFIG_MODULES
8
-
9
-typedef void (*cfi_check_fn)(uint64_t, void *, void *);
11
+typedef void (*cfi_check_fn)(uint64_t id, void *ptr, void *diag);
1012
1113 /* Compiler-generated function in each module, and the kernel */
12
-#define CFI_CHECK_FN __cfi_check
13
-#define CFI_CHECK_FN_NAME __stringify(CFI_CHECK_FN)
14
+extern void __cfi_check(uint64_t id, void *ptr, void *diag);
1415
15
-extern void CFI_CHECK_FN(uint64_t, void *, void *);
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;
1622
1723 #ifdef CONFIG_CFI_CLANG_SHADOW
18
-extern void cfi_module_add(struct module *mod, unsigned long min_addr,
19
- unsigned long max_addr);
2024
21
-extern void cfi_module_remove(struct module *mod, unsigned long min_addr,
22
- unsigned long max_addr);
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
+
2328 #else
24
-static inline void cfi_module_add(struct module *mod, unsigned long min_addr,
25
- unsigned long max_addr)
26
-{
27
-}
2829
29
-static inline void cfi_module_remove(struct module *mod, unsigned long min_addr,
30
- unsigned long max_addr)
31
-{
32
-}
30
+static inline void cfi_module_add(struct module *mod, unsigned long base_addr) {}
31
+static inline void cfi_module_remove(struct module *mod, unsigned long base_addr) {}
32
+
3333 #endif /* CONFIG_CFI_CLANG_SHADOW */
3434
35
-#endif /* CONFIG_MODULES */
35
+#else /* !CONFIG_CFI_CLANG */
36
+
37
+#define __CFI_ADDRESSABLE(fn)
38
+
3639 #endif /* CONFIG_CFI_CLANG */
3740
3841 #endif /* _LINUX_CFI_H */