Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Clang Control Flow Integrity (CFI) support.
0004  *
0005  * Copyright (C) 2021 Google LLC
0006  */
0007 #ifndef _LINUX_CFI_H
0008 #define _LINUX_CFI_H
0009 
0010 #ifdef CONFIG_CFI_CLANG
0011 typedef void (*cfi_check_fn)(uint64_t id, void *ptr, void *diag);
0012 
0013 /* Compiler-generated function in each module, and the kernel */
0014 extern void __cfi_check(uint64_t id, void *ptr, void *diag);
0015 
0016 /*
0017  * Force the compiler to generate a CFI jump table entry for a function
0018  * and store the jump table address to __cfi_jt_<function>.
0019  */
0020 #define __CFI_ADDRESSABLE(fn, __attr) \
0021     const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn
0022 
0023 #ifdef CONFIG_CFI_CLANG_SHADOW
0024 
0025 extern void cfi_module_add(struct module *mod, unsigned long base_addr);
0026 extern void cfi_module_remove(struct module *mod, unsigned long base_addr);
0027 
0028 #else
0029 
0030 static inline void cfi_module_add(struct module *mod, unsigned long base_addr) {}
0031 static inline void cfi_module_remove(struct module *mod, unsigned long base_addr) {}
0032 
0033 #endif /* CONFIG_CFI_CLANG_SHADOW */
0034 
0035 #else /* !CONFIG_CFI_CLANG */
0036 
0037 #ifdef CONFIG_X86_KERNEL_IBT
0038 
0039 #define __CFI_ADDRESSABLE(fn, __attr) \
0040     const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn
0041 
0042 #endif /* CONFIG_X86_KERNEL_IBT */
0043 
0044 #endif /* CONFIG_CFI_CLANG */
0045 
0046 #ifndef __CFI_ADDRESSABLE
0047 #define __CFI_ADDRESSABLE(fn, __attr)
0048 #endif
0049 
0050 #endif /* _LINUX_CFI_H */