File tree 5 files changed +17
-2
lines changed
5 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -976,8 +976,19 @@ export CC_FLAGS_LTO
976
976
endif
977
977
978
978
ifdef CONFIG_CFI_CLANG
979
- CC_FLAGS_CFI := -fsanitize=kcfi
980
- KBUILD_CFLAGS += $(CC_FLAGS_CFI )
979
+ CC_FLAGS_CFI := -fsanitize=kcfi
980
+ ifdef CONFIG_RUST
981
+ # If Rust is enabled, this flag is required to support cross-language
982
+ # integer types.
983
+ # This addresses the problem that on e.g. i686, int != long, and Rust
984
+ # maps both to i32.
985
+ # See https://rcvalle.com/docs/rust-cfi-design-doc.pdf for details.
986
+ CC_FLAGS_CFI += -fsanitize-cfi-icall-experimental-normalize-integers
987
+ RS_FLAGS_CFI := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers
988
+ KBUILD_RSFLAGS += RS_FLAGS_CFI
989
+ export RS_FLAGS_CFI
990
+ endif
991
+ KBUILD_CFLAGS += $(CC_FLAGS_CFI )
981
992
export CC_FLAGS_CFI
982
993
endif
983
994
Original file line number Diff line number Diff line change @@ -81,6 +81,7 @@ ifeq ($(CONFIG_X86_KERNEL_IBT),y)
81
81
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104816
82
82
#
83
83
KBUILD_CFLAGS += $(call cc-option,-fcf-protection=branch -fno-jump-tables)
84
+ KBUILD_RUSTFLAGS += -Zcf-protection=branch -Zno-jump-tables
84
85
else
85
86
KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none)
86
87
endif
Original file line number Diff line number Diff line change @@ -1889,6 +1889,7 @@ config RUST
1889
1889
depends on !GCC_PLUGINS
1890
1890
depends on !RANDSTRUCT
1891
1891
depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE
1892
+ depends on !CFI_CLANG || $(cc-option,-fsanitize=kcfi,-fsanitize-cfi-icall-experimental-normalize-integers)
1892
1893
select CONSTRUCTORS
1893
1894
help
1894
1895
Enables Rust support in the kernel.
Original file line number Diff line number Diff line change @@ -365,6 +365,7 @@ quiet_cmd_exports = EXPORTS $@
365
365
cmd_exports = \
366
366
$(NM ) -p --defined-only $< \
367
367
| grep -E ' (T|R|D) ' | cut -d ' ' -f 3 \
368
+ | grep -v ^__cfi \
368
369
| xargs -Isymbol \
369
370
echo 'EXPORT_SYMBOL_RUST_GPL(symbol);' > $@
370
371
Original file line number Diff line number Diff line change @@ -178,6 +178,7 @@ fn main() {
178
178
}
179
179
ts. push ( "features" , features) ;
180
180
ts. push ( "llvm-target" , "x86_64-linux-gnu" ) ;
181
+ ts. push ( "supported-sanitizers" , [ "kcfi" ] ) ;
181
182
ts. push ( "target-pointer-width" , "64" ) ;
182
183
} else {
183
184
panic ! ( "Unsupported architecture" ) ;
You can’t perform that action at this time.
0 commit comments