cfi: Add CFI_NOSEAL()
authorPeter Zijlstra <peterz@infradead.org>
Fri, 15 Dec 2023 09:12:21 +0000 (10:12 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 16 Dec 2023 00:25:55 +0000 (16:25 -0800)
Add a CFI_NOSEAL() helper to mark functions that need to retain their
CFI information, despite not otherwise leaking their address.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20231215092707.669401084@infradead.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
arch/x86/include/asm/cfi.h
include/linux/cfi.h

index 1a50b2cd4713853d8f65d7df6a2f62dfb71e32bf..7cd7525579051d06a8bd670d6be24c103a0fe764 100644 (file)
@@ -8,6 +8,7 @@
  * Copyright (C) 2022 Google LLC
  */
 #include <linux/bug.h>
+#include <asm/ibt.h>
 
 /*
  * An overview of the various calling conventions...
@@ -138,4 +139,8 @@ static inline u32 cfi_get_func_hash(void *func)
 }
 #endif /* CONFIG_CFI_CLANG */
 
+#if HAS_KERNEL_IBT == 1
+#define CFI_NOSEAL(x)  asm(IBT_NOSEAL(__stringify(x)))
+#endif
+
 #endif /* _ASM_X86_CFI_H */
index 1ed2d96c0cfc8061c2d94f4611117e4de2ff5820..f0df518e11dd15a63aa3561355f71afe66c45e9f 100644 (file)
@@ -46,4 +46,8 @@ static inline void module_cfi_finalize(const Elf_Ehdr *hdr,
 #endif /* CONFIG_ARCH_USES_CFI_TRAPS */
 #endif /* CONFIG_MODULES */
 
+#ifndef CFI_NOSEAL
+#define CFI_NOSEAL(x)
+#endif
+
 #endif /* _LINUX_CFI_H */