cfi.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Clang Control Flow Integrity (CFI) support.
  4. *
  5. * Copyright (C) 2022 Google LLC
  6. */
  7. #ifndef _LINUX_CFI_H
  8. #define _LINUX_CFI_H
  9. #include <linux/bug.h>
  10. #include <linux/module.h>
  11. #ifdef CONFIG_CFI_CLANG
  12. enum bug_trap_type report_cfi_failure(struct pt_regs *regs, unsigned long addr,
  13. unsigned long *target, u32 type);
  14. static inline enum bug_trap_type report_cfi_failure_noaddr(struct pt_regs *regs,
  15. unsigned long addr)
  16. {
  17. return report_cfi_failure(regs, addr, NULL, 0);
  18. }
  19. #ifdef CONFIG_ARCH_USES_CFI_TRAPS
  20. bool is_cfi_trap(unsigned long addr);
  21. #endif
  22. #endif /* CONFIG_CFI_CLANG */
  23. #ifdef CONFIG_MODULES
  24. #ifdef CONFIG_ARCH_USES_CFI_TRAPS
  25. void module_cfi_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
  26. struct module *mod);
  27. #else
  28. static inline void module_cfi_finalize(const Elf_Ehdr *hdr,
  29. const Elf_Shdr *sechdrs,
  30. struct module *mod) {}
  31. #endif /* CONFIG_ARCH_USES_CFI_TRAPS */
  32. #endif /* CONFIG_MODULES */
  33. #endif /* _LINUX_CFI_H */