Skip to content

Commit 39c89ee

Browse files
nathanchancekees
authored andcommitted
compiler_types: Introduce __nocfi_generic
There are two different ways that LLVM can expand kCFI operand bundles in LLVM IR: generically in the middle end or using an architecture specific sequence when lowering LLVM IR to machine code in the backend. The generic pass allows any architecture to take advantage of kCFI but the expansion of these bundles in the middle end can mess with optimizations that may turn indirect calls into direct calls when the call target is known at compile time, such as after inlining. Add __nocfi_generic, dependent on an architecture selecting CONFIG_ARCH_USES_CFI_GENERIC_LLVM_PASS, to disable kCFI bundle generation in functions where only the generic kCFI pass may cause problems. Link: ClangBuiltLinux#2124 Signed-off-by: Nathan Chancellor <nathan@kernel.org> Link: https://patch.msgid.link/20251025-idpf-fix-arm-kcfi-build-error-v1-1-ec57221153ae@kernel.org Signed-off-by: Kees Cook <kees@kernel.org>
1 parent 211ddde commit 39c89ee

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

arch/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,13 @@ config ARCH_USES_CFI_TRAPS
917917
An architecture should select this option if it requires the
918918
.kcfi_traps section for KCFI trap handling.
919919

920+
config ARCH_USES_CFI_GENERIC_LLVM_PASS
921+
bool
922+
help
923+
An architecture should select this option if it uses the generic
924+
KCFIPass in LLVM to expand kCFI bundles instead of architecture-specific
925+
lowering.
926+
920927
config CFI
921928
bool "Use Kernel Control Flow Integrity (kCFI)"
922929
default CFI_CLANG

include/linux/compiler_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,12 @@ struct ftrace_likely_data {
461461
# define __nocfi
462462
#endif
463463

464+
#if defined(CONFIG_ARCH_USES_CFI_GENERIC_LLVM_PASS)
465+
# define __nocfi_generic __nocfi
466+
#else
467+
# define __nocfi_generic
468+
#endif
469+
464470
/*
465471
* Any place that could be marked with the "alloc_size" attribute is also
466472
* a place to be marked with the "malloc" attribute, except those that may

0 commit comments

Comments
 (0)