Since the integer wrapping sanitizer's behavior depends on its associated .scl file, we must force a full rebuild if the file changes. Universally include a synthetic header file that is rebuilt when the .scl file changes, via compiler-version.h, since using "-include ..." is not possible in the case of having compiler flags removed via "filter-out" (which would remove all instances of "-include").
Signed-off-by: Kees Cook <k...@kernel.org> --- Cc: Masahiro Yamada <masahi...@kernel.org> Cc: Justin Stitt <justinst...@google.com> Cc: Nathan Chancellor <nat...@kernel.org> Cc: Nicolas Schier <nicolas.sch...@linux.dev> Cc: Marco Elver <el...@google.com> Cc: Andrey Konovalov <andreyk...@gmail.com> Cc: Andrey Ryabinin <ryabinin....@gmail.com> Cc: <linux-kbu...@vger.kernel.org> Cc: <kasan-...@googlegroups.com> Cc: <linux-harden...@vger.kernel.org> --- include/linux/compiler-version.h | 3 +++ scripts/Makefile.ubsan | 1 + scripts/basic/Makefile | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/include/linux/compiler-version.h b/include/linux/compiler-version.h index 05d555320a0f..9d6b1890ffc7 100644 --- a/include/linux/compiler-version.h +++ b/include/linux/compiler-version.h @@ -19,3 +19,6 @@ #ifdef RANDSTRUCT #include "randstruct_hash.h" #endif +#ifdef INTEGER_WRAP +#include "integer-wrap.h" +#endif diff --git a/scripts/Makefile.ubsan b/scripts/Makefile.ubsan index 9e35198edbf0..653f7117819c 100644 --- a/scripts/Makefile.ubsan +++ b/scripts/Makefile.ubsan @@ -15,6 +15,7 @@ ubsan-cflags-$(CONFIG_UBSAN_TRAP) += $(call cc-option,-fsanitize-trap=undefined export CFLAGS_UBSAN := $(ubsan-cflags-y) ubsan-integer-wrap-cflags-$(CONFIG_UBSAN_INTEGER_WRAP) += \ + -DINTEGER_WRAP \ -fsanitize-undefined-ignore-overflow-pattern=all \ -fsanitize=signed-integer-overflow \ -fsanitize=unsigned-integer-overflow \ diff --git a/scripts/basic/Makefile b/scripts/basic/Makefile index 31637ce4dc5c..04f5620a3f8b 100644 --- a/scripts/basic/Makefile +++ b/scripts/basic/Makefile @@ -15,3 +15,12 @@ $(obj)/randstruct_hash.h $(obj)/randstruct.seed: $(gen-randstruct-seed) FORCE $(call if_changed,create_randstruct_seed) always-$(CONFIG_RANDSTRUCT) += randstruct.seed randstruct_hash.h + +# integer-wrap: if the .scl file changes, we need to do a full rebuild. +quiet_cmd_integer_wrap_updated = UPDATE $@ + cmd_integer_wrap_updated = echo '/* $^ */' > $(obj)/integer-wrap.h + +$(obj)/integer-wrap.h: $(srctree)/scripts/integer-wrap-ignore.scl FORCE + $(call if_changed,integer_wrap_updated) + +always-$(CONFIG_UBSAN_INTEGER_WRAP) += integer-wrap.h -- 2.34.1