Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dde953e

Browse files
Darksonnojeda
authored andcommittedOct 10, 2024
cfi: fix conditions for HAVE_CFI_ICALL_NORMALIZE_INTEGERS
The HAVE_CFI_ICALL_NORMALIZE_INTEGERS option has some tricky conditions when KASAN or GCOV are turned on, as in that case we need some clang and rustc fixes [1][2] to avoid boot failures. The intent with the current setup is that you should be able to override the check and turn on the option if your clang/rustc has the fix. However, this override does not work in practice. Thus, use the new RUSTC_LLVM_VERSION to correctly implement the check for whether the fix is available. Additionally, remove KASAN_HW_TAGS from the list of incompatible options. The CFI_ICALL_NORMALIZE_INTEGERS option is incompatible with KASAN because LLVM will emit some constructors when using KASAN that are assigned incorrect CFI tags. These constructors are emitted due to use of -fsanitize=kernel-address or -fsanitize=kernel-hwaddress that are respectively passed when KASAN_GENERIC or KASAN_SW_TAGS are enabled. However, the KASAN_HW_TAGS option relies on hardware support for MTE instead and does not pass either flag. (Note also that KASAN_HW_TAGS does not `select CONSTRUCTORS`.) Link: llvm/llvm-project#104826 [1] Link: rust-lang/rust#129373 [2] Fixes: 4c66f83 ("cfi: encode cfi normalized integers + kasan/gcov bug in Kconfig") Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Sami Tolvanen <samitolvanen@google.com> Link: https://lore.kernel.org/r/20241010-icall-detect-vers-v1-2-8f114956aa88@google.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 89a9dc6 commit dde953e

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed
 

‎arch/Kconfig

+12-14
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ config CFI_CLANG
838838
config CFI_ICALL_NORMALIZE_INTEGERS
839839
bool "Normalize CFI tags for integers"
840840
depends on CFI_CLANG
841-
depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS
841+
depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS_CLANG
842842
help
843843
This option normalizes the CFI tags for integer types so that all
844844
integer types of the same size and signedness receive the same CFI
@@ -851,21 +851,19 @@ config CFI_ICALL_NORMALIZE_INTEGERS
851851

852852
This option is necessary for using CFI with Rust. If unsure, say N.
853853

854-
config HAVE_CFI_ICALL_NORMALIZE_INTEGERS
855-
def_bool !GCOV_KERNEL && !KASAN
856-
depends on CFI_CLANG
854+
config HAVE_CFI_ICALL_NORMALIZE_INTEGERS_CLANG
855+
def_bool y
857856
depends on $(cc-option,-fsanitize=kcfi -fsanitize-cfi-icall-experimental-normalize-integers)
858-
help
859-
Is CFI_ICALL_NORMALIZE_INTEGERS supported with the set of compilers
860-
currently in use?
857+
# With GCOV/KASAN we need this fix: https://github.com/llvm/llvm-project/pull/104826
858+
depends on CLANG_VERSION >= 190000 || (!GCOV_KERNEL && !KASAN_GENERIC && !KASAN_SW_TAGS)
861859

862-
This option defaults to false if GCOV or KASAN is enabled, as there is
863-
an LLVM bug that makes normalized integers tags incompatible with
864-
KASAN and GCOV. Kconfig currently does not have the infrastructure to
865-
detect whether your rustc compiler contains the fix for this bug, so
866-
it is assumed that it doesn't. If your compiler has the fix, you can
867-
explicitly enable this option in your config file. The Kconfig logic
868-
needed to detect this will be added in a future kernel release.
860+
config HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC
861+
def_bool y
862+
depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS_CLANG
863+
depends on RUSTC_VERSION >= 107900
864+
# With GCOV/KASAN we need this fix: https://github.com/rust-lang/rust/pull/129373
865+
depends on (RUSTC_LLVM_VERSION >= 190000 && RUSTC_VERSION >= 108200) || \
866+
(!GCOV_KERNEL && !KASAN_GENERIC && !KASAN_SW_TAGS)
869867

870868
config CFI_PERMISSIVE
871869
bool "Use CFI in permissive mode"

‎init/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,7 @@ config RUST
19501950
depends on !GCC_PLUGIN_RANDSTRUCT
19511951
depends on !RANDSTRUCT
19521952
depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE
1953-
depends on !CFI_CLANG || RUSTC_VERSION >= 107900 && HAVE_CFI_ICALL_NORMALIZE_INTEGERS
1953+
depends on !CFI_CLANG || HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC
19541954
select CFI_ICALL_NORMALIZE_INTEGERS if CFI_CLANG
19551955
depends on !CALL_PADDING || RUSTC_VERSION >= 108100
19561956
depends on !KASAN_SW_TAGS

0 commit comments

Comments
 (0)
Failed to load comments.