Skip to content

Commit 23ef9d4

Browse files
committed
kcfi: Rename CONFIG_CFI_CLANG to CONFIG_CFI
The kernel's CFI implementation uses the KCFI ABI specifically, and is not strictly tied to a particular compiler. In preparation for GCC supporting KCFI, rename CONFIG_CFI_CLANG to CONFIG_CFI (along with associated options). Use new "transitional" Kconfig option for old CONFIG_CFI_CLANG that will enable CONFIG_CFI during olddefconfig. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Nathan Chancellor <nathan@kernel.org> Link: https://lore.kernel.org/r/20250923213422.1105654-3-kees@kernel.org Signed-off-by: Kees Cook <kees@kernel.org>
1 parent f9afce4 commit 23ef9d4

55 files changed

Lines changed: 100 additions & 90 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ KBUILD_AFLAGS += -fno-lto
10201020
export CC_FLAGS_LTO
10211021
endif
10221022

1023-
ifdef CONFIG_CFI_CLANG
1023+
ifdef CONFIG_CFI
10241024
CC_FLAGS_CFI := -fsanitize=kcfi
10251025
ifdef CONFIG_CFI_ICALL_NORMALIZE_INTEGERS
10261026
CC_FLAGS_CFI += -fsanitize-cfi-icall-experimental-normalize-integers

arch/Kconfig

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -867,22 +867,26 @@ config PROPELLER_CLANG
867867

868868
If unsure, say N.
869869

870-
config ARCH_SUPPORTS_CFI_CLANG
870+
config ARCH_SUPPORTS_CFI
871871
bool
872872
help
873-
An architecture should select this option if it can support Clang's
874-
Control-Flow Integrity (CFI) checking.
873+
An architecture should select this option if it can support Kernel
874+
Control-Flow Integrity (CFI) checking (-fsanitize=kcfi).
875875

876876
config ARCH_USES_CFI_TRAPS
877877
bool
878+
help
879+
An architecture should select this option if it requires the
880+
.kcfi_traps section for KCFI trap handling.
878881

879-
config CFI_CLANG
880-
bool "Use Clang's Control Flow Integrity (CFI)"
881-
depends on ARCH_SUPPORTS_CFI_CLANG
882+
config CFI
883+
bool "Use Kernel Control Flow Integrity (kCFI)"
884+
default CFI_CLANG
885+
depends on ARCH_SUPPORTS_CFI
882886
depends on $(cc-option,-fsanitize=kcfi)
883887
help
884-
This option enables Clang's forward-edge Control Flow Integrity
885-
(CFI) checking, where the compiler injects a runtime check to each
888+
This option enables forward-edge Control Flow Integrity (CFI)
889+
checking, where the compiler injects a runtime check to each
886890
indirect function call to ensure the target is a valid function with
887891
the correct static type. This restricts possible call targets and
888892
makes it more difficult for an attacker to exploit bugs that allow
@@ -891,10 +895,16 @@ config CFI_CLANG
891895

892896
https://clang.llvm.org/docs/ControlFlowIntegrity.html
893897

898+
config CFI_CLANG
899+
bool
900+
transitional
901+
help
902+
Transitional config for CFI_CLANG to CFI migration.
903+
894904
config CFI_ICALL_NORMALIZE_INTEGERS
895905
bool "Normalize CFI tags for integers"
896-
depends on CFI_CLANG
897-
depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS_CLANG
906+
depends on CFI
907+
depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS
898908
help
899909
This option normalizes the CFI tags for integer types so that all
900910
integer types of the same size and signedness receive the same CFI
@@ -907,23 +917,23 @@ config CFI_ICALL_NORMALIZE_INTEGERS
907917

908918
This option is necessary for using CFI with Rust. If unsure, say N.
909919

910-
config HAVE_CFI_ICALL_NORMALIZE_INTEGERS_CLANG
920+
config HAVE_CFI_ICALL_NORMALIZE_INTEGERS
911921
def_bool y
912922
depends on $(cc-option,-fsanitize=kcfi -fsanitize-cfi-icall-experimental-normalize-integers)
913923
# With GCOV/KASAN we need this fix: https://github.com/llvm/llvm-project/pull/104826
914924
depends on CLANG_VERSION >= 190103 || (!GCOV_KERNEL && !KASAN_GENERIC && !KASAN_SW_TAGS)
915925

916926
config HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC
917927
def_bool y
918-
depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS_CLANG
928+
depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS
919929
depends on RUSTC_VERSION >= 107900
920930
# With GCOV/KASAN we need this fix: https://github.com/rust-lang/rust/pull/129373
921931
depends on (RUSTC_LLVM_VERSION >= 190103 && RUSTC_VERSION >= 108200) || \
922932
(!GCOV_KERNEL && !KASAN_GENERIC && !KASAN_SW_TAGS)
923933

924934
config CFI_PERMISSIVE
925935
bool "Use CFI in permissive mode"
926-
depends on CFI_CLANG
936+
depends on CFI
927937
help
928938
When selected, Control Flow Integrity (CFI) violations result in a
929939
warning instead of a kernel panic. This option should only be used

arch/arm/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ config ARM
3838
select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT if CPU_V7
3939
select ARCH_NEED_CMPXCHG_1_EMU if CPU_V6
4040
select ARCH_SUPPORTS_ATOMIC_RMW
41-
select ARCH_SUPPORTS_CFI_CLANG
41+
select ARCH_SUPPORTS_CFI
4242
select ARCH_SUPPORTS_HUGETLBFS if ARM_LPAE
4343
select ARCH_SUPPORTS_PER_VMA_LOCK
4444
select ARCH_USE_BUILTIN_BSWAP

arch/arm/kernel/hw_breakpoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ static void breakpoint_handler(unsigned long unknown, struct pt_regs *regs)
904904
watchpoint_single_step_handler(addr);
905905
}
906906

907-
#ifdef CONFIG_CFI_CLANG
907+
#ifdef CONFIG_CFI
908908
static void hw_breakpoint_cfi_handler(struct pt_regs *regs)
909909
{
910910
/*

arch/arm/mm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ obj-$(CONFIG_CPU_V6) += proc-v6.o
8989
obj-$(CONFIG_CPU_V6K) += proc-v6.o
9090
obj-$(CONFIG_CPU_V7) += proc-v7.o proc-v7-bugs.o
9191
obj-$(CONFIG_CPU_V7M) += proc-v7m.o
92-
obj-$(CONFIG_CFI_CLANG) += proc.o
92+
obj-$(CONFIG_CFI) += proc.o
9393

9494
obj-$(CONFIG_OUTER_CACHE) += l2c-common.o
9595
obj-$(CONFIG_CACHE_B15_RAC) += cache-b15-rac.o

arch/arm/mm/cache-fa.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ SYM_FUNC_END(fa_flush_user_cache_range)
112112
* - end - virtual end address
113113
*/
114114
SYM_TYPED_FUNC_START(fa_coherent_kern_range)
115-
#ifdef CONFIG_CFI_CLANG /* Fallthrough if !CFI */
115+
#ifdef CONFIG_CFI /* Fallthrough if !CFI */
116116
b fa_coherent_user_range
117117
#endif
118118
SYM_FUNC_END(fa_coherent_kern_range)

arch/arm/mm/cache-v4.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ SYM_FUNC_END(v4_coherent_user_range)
104104
* - size - region size
105105
*/
106106
SYM_TYPED_FUNC_START(v4_flush_kern_dcache_area)
107-
#ifdef CONFIG_CFI_CLANG /* Fallthrough if !CFI */
107+
#ifdef CONFIG_CFI /* Fallthrough if !CFI */
108108
b v4_dma_flush_range
109109
#endif
110110
SYM_FUNC_END(v4_flush_kern_dcache_area)

arch/arm/mm/cache-v4wb.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ SYM_FUNC_END(v4wb_flush_user_cache_range)
136136
*/
137137
SYM_TYPED_FUNC_START(v4wb_flush_kern_dcache_area)
138138
add r1, r0, r1
139-
#ifdef CONFIG_CFI_CLANG /* Fallthrough if !CFI */
139+
#ifdef CONFIG_CFI /* Fallthrough if !CFI */
140140
b v4wb_coherent_user_range
141141
#endif
142142
SYM_FUNC_END(v4wb_flush_kern_dcache_area)
@@ -152,7 +152,7 @@ SYM_FUNC_END(v4wb_flush_kern_dcache_area)
152152
* - end - virtual end address
153153
*/
154154
SYM_TYPED_FUNC_START(v4wb_coherent_kern_range)
155-
#ifdef CONFIG_CFI_CLANG /* Fallthrough if !CFI */
155+
#ifdef CONFIG_CFI /* Fallthrough if !CFI */
156156
b v4wb_coherent_user_range
157157
#endif
158158
SYM_FUNC_END(v4wb_coherent_kern_range)

arch/arm/mm/cache-v4wt.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ SYM_FUNC_END(v4wt_flush_user_cache_range)
108108
* - end - virtual end address
109109
*/
110110
SYM_TYPED_FUNC_START(v4wt_coherent_kern_range)
111-
#ifdef CONFIG_CFI_CLANG /* Fallthrough if !CFI */
111+
#ifdef CONFIG_CFI /* Fallthrough if !CFI */
112112
b v4wt_coherent_user_range
113113
#endif
114114
SYM_FUNC_END(v4wt_coherent_kern_range)

arch/arm/mm/cache-v6.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ SYM_FUNC_END(v6_flush_user_cache_range)
117117
* - the Icache does not read data from the write buffer
118118
*/
119119
SYM_TYPED_FUNC_START(v6_coherent_kern_range)
120-
#ifdef CONFIG_CFI_CLANG /* Fallthrough if !CFI */
120+
#ifdef CONFIG_CFI /* Fallthrough if !CFI */
121121
b v6_coherent_user_range
122122
#endif
123123
SYM_FUNC_END(v6_coherent_kern_range)

0 commit comments

Comments
 (0)