integer-wrap: Force full rebuild when .scl file changes
authorKees Cook <kees@kernel.org>
Sat, 3 May 2025 18:46:20 +0000 (11:46 -0700)
committerKees Cook <kees@kernel.org>
Thu, 8 May 2025 16:42:06 +0000 (09:42 -0700)
Since the integer wrapping sanitizer's behavior depends on its associated
.scl file, we must force a full rebuild if the file changes. If not,
instrumentation may differ between targets based on when they were built.

Generate a new header file, integer-wrap.h, any time the Clang .scl
file changes. Include the header file in compiler-version.h when its
associated feature name, INTEGER_WRAP, is defined. This will be picked
up by fixdep and force rebuilds where needed.

Acked-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20250503184623.2572355-3-kees@kernel.org
Reviewed-by: Nicolas Schier <n.schier@avm.de>
Signed-off-by: Kees Cook <kees@kernel.org>
include/linux/compiler-version.h
scripts/Makefile.ubsan
scripts/basic/Makefile

index 4b9d39b3765033aae05dcc8b7f9f5c0fe524bc5a..ac1665a98a15db4ba9a9c1af968d81b3d928a0eb 100644 (file)
 #ifdef RANDSTRUCT
 #include <generated/randstruct_hash.h>
 #endif
+
+/*
+ * If any external changes affect Clang's integer wrapping sanitizer
+ * behavior, a full rebuild is needed as the coverage for wrapping types
+ * may have changed, which may impact the expected behaviors that should
+ * not differ between compilation units.
+ */
+#ifdef INTEGER_WRAP
+#include <generated/integer-wrap.h>
+#endif
index 9e35198edbf0d08d7b281cd43d882046a84e4e37..653f7117819ca23b4c399acd694efdb3334573c1 100644 (file)
@@ -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                    \
index dd289a6725aca60c596ae4c7ec831775b98a495a..fb8e2c38fbc783c6bd3beecddc0fce84afcc042c 100644 (file)
@@ -14,3 +14,8 @@ cmd_create_randstruct_seed = \
 $(obj)/randstruct.seed: $(gen-randstruct-seed) FORCE
        $(call if_changed,create_randstruct_seed)
 always-$(CONFIG_RANDSTRUCT) += randstruct.seed
+
+# integer-wrap: if the .scl file changes, we need to do a full rebuild.
+$(obj)/../../include/generated/integer-wrap.h: $(srctree)/scripts/integer-wrap-ignore.scl FORCE
+       $(call if_changed,touch)
+always-$(CONFIG_UBSAN_INTEGER_WRAP) += ../../include/generated/integer-wrap.h