randstruct: Force full rebuild when seed changes
authorKees Cook <kees@kernel.org>
Sat, 3 May 2025 18:46:19 +0000 (11:46 -0700)
committerKees Cook <kees@kernel.org>
Thu, 8 May 2025 16:42:06 +0000 (09:42 -0700)
While the randstruct GCC plugin was being rebuilt if the randstruct seed
changed, Clang builds did not notice the change. This could result in
differing struct layouts in a target depending on when it was built.

Include the existing generated header file in compiler-version.h when
its associated feature name, RANDSTRUCT, is defined. This will be picked
up by fixdep and force rebuilds where needed.

Link: https://lore.kernel.org/r/20250503184623.2572355-2-kees@kernel.org
Reviewed-by: Nicolas Schier <n.schier@avm.de>
Tested-by: Nicolas Schier <n.schier@avm.de>
Signed-off-by: Kees Cook <kees@kernel.org>
include/linux/compiler-version.h
include/linux/vermagic.h

index 5dba398a94129e099bda81ba79bdb45a08ac630c..4b9d39b3765033aae05dcc8b7f9f5c0fe524bc5a 100644 (file)
 #ifdef GCC_PLUGINS
 #include <generated/gcc-plugins.h>
 #endif
+
+/*
+ * If the randstruct seed itself changes (whether for GCC plugins or
+ * Clang), the entire tree needs to be rebuilt since the randomization of
+ * structures may change between compilation units if not.
+ */
+#ifdef RANDSTRUCT
+#include <generated/randstruct_hash.h>
+#endif
index 939ceabcaf06f3739929b19ce4c3f20aec6a950e..335c360d4f9b94d73cd91e57c27466514323cbd6 100644 (file)
@@ -33,7 +33,6 @@
 #define MODULE_VERMAGIC_MODVERSIONS ""
 #endif
 #ifdef RANDSTRUCT
-#include <generated/randstruct_hash.h>
 #define MODULE_RANDSTRUCT "RANDSTRUCT_" RANDSTRUCT_HASHED_SEED
 #else
 #define MODULE_RANDSTRUCT