ANDROID: Makefile: Fail the build if RUST and CFI are both enabled

Enabling CONFIG_RUST changes the compiler's CFI flags so that we pass
'-fsanitize-cfi-icall-experimental-normalize-integers'. This results in
a silent KMI break (i.e. one which is not detected by our ABI tooling)
and has been shown to prevent loading of modules which differ from the
kernel in their value of CONFIG_RUST:

  | init: Loading module /lib/modules/6.6.30-android15-8-maybe-dirty-4k/kernel/mm/zsmalloc.ko with args ''
  | CFI failure at do_one_initcall+0xd4/0x360 (target: init_module+0x0/0xfe4 [zsmalloc]; expected type: 0x6fbb3035)
  | Internal error: Oops - CFI: 00000000f2008233 [#1] PREEMPT SMP

To help avoid this silent KMI breakage in the future on android15-6.6,
add a diagnostic error to the top-level Makefile when both RUST and CFI
are enabled.

Bug: 350371019
Cc: Matthias Männich <maennich@google.com>
Signed-off-by: Will Deacon <willdeacon@google.com>
Change-Id: Ib6cbcc0010f6c76dfbf0ae2cd7ae004217405ed9
This commit is contained in:
Will Deacon 2024-07-03 12:57:37 +01:00 committed by Treehugger Robot
parent 437e699ef9
commit 691810c3b9

View File

@ -1009,6 +1009,7 @@ ifdef CONFIG_RUST
# This addresses the problem that on e.g. i686, int != long, and Rust
# maps both to i32.
# See https://rcvalle.com/docs/rust-cfi-design-doc.pdf for details.
$(error "Enabling Rust and CFI silently changes the KMI.")
CC_FLAGS_CFI += -fsanitize-cfi-icall-experimental-normalize-integers
RS_FLAGS_CFI := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers
KBUILD_RUSTFLAGS += $(RS_FLAGS_CFI)