File tree 4 files changed +16
-3
lines changed
4 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -967,8 +967,19 @@ export CC_FLAGS_LTO
967
967
endif
968
968
969
969
ifdef CONFIG_CFI_CLANG
970
- CC_FLAGS_CFI := -fsanitize=kcfi
971
- KBUILD_CFLAGS += $(CC_FLAGS_CFI )
970
+ CC_FLAGS_CFI := -fsanitize=kcfi
971
+ ifdef CONFIG_RUST
972
+ # If Rust is enabled, this flag is required to support cross-language
973
+ # integer types.
974
+ # This addresses the problem that on e.g. i686, int != long, and Rust
975
+ # maps both to i32.
976
+ # See https://rcvalle.com/docs/rust-cfi-design-doc.pdf for details.
977
+ CC_FLAGS_CFI += -fsanitize-cfi-icall-experimental-normalize-integers
978
+ RS_FLAGS_CFI := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers
979
+ KBUILD_RSFLAGS += RS_FLAGS_CFI
980
+ export RS_FLAGS_CFI
981
+ endif
982
+ KBUILD_CFLAGS += $(CC_FLAGS_CFI )
972
983
export CC_FLAGS_CFI
973
984
endif
974
985
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 @@ -364,7 +364,7 @@ $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers.c FORCE
364
364
quiet_cmd_exports = EXPORTS $@
365
365
cmd_exports = \
366
366
$(NM ) -p --defined-only $< \
367
- | awk '/ (T|R|D) / {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@
367
+ | awk '$$2~/ (T|R|D)/ && $$3!~/__cfi / {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@
368
368
369
369
$(obj ) /exports_core_generated.h : $(obj ) /core.o FORCE
370
370
$(call if_changed,exports)
Original file line number Diff line number Diff line change @@ -179,6 +179,7 @@ fn main() {
179
179
}
180
180
ts. push ( "features" , features) ;
181
181
ts. push ( "llvm-target" , "x86_64-linux-gnu" ) ;
182
+ ts. push ( "supported-sanitizers" , [ "kcfi" ] ) ;
182
183
ts. push ( "target-pointer-width" , "64" ) ;
183
184
} else {
184
185
panic ! ( "Unsupported architecture" ) ;
You can’t perform that action at this time.
0 commit comments