xref: /linux-6.15/include/linux/cfi.h (revision 9fca7115)
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
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, __attr) \
21 	const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn
22 
23 #else /* !CONFIG_CFI_CLANG */
24 
25 #ifdef CONFIG_X86_KERNEL_IBT
26 
27 #define __CFI_ADDRESSABLE(fn, __attr) \
28 	const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn
29 
30 #endif /* CONFIG_X86_KERNEL_IBT */
31 
32 #endif /* CONFIG_CFI_CLANG */
33 
34 #ifndef __CFI_ADDRESSABLE
35 #define __CFI_ADDRESSABLE(fn, __attr)
36 #endif
37 
38 #endif /* _LINUX_CFI_H */
39