* [PATCH] randstruct: Rebuild completely if randstruct.seed changes
@ 2025-04-29 12:59 Nicolas Schier
2025-04-29 13:11 ` Miguel Ojeda
2025-04-29 16:52 ` Kees Cook
0 siblings, 2 replies; 3+ messages in thread
From: Nicolas Schier @ 2025-04-29 12:59 UTC (permalink / raw)
To: Kees Cook, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich
Cc: Masahiro Yamada, Nicolas Schier, linux-hardening, linux-kbuild,
linux-kernel, rust-for-linux, Nicolas Schier
Include generated/randstruct_hash.h in linux/compiler-version.h to force
a complete rebuild if CONFIG_RANDSTRUCT is enabled and randstruct.seed
changes.
Removal or change of scripts/basic/randstruct.seed leads to a remake of
generated/randstruct_hash.h. As linux/compiler-version.h is a
hard-coded include for every kbuild induced compilation, conditionally
adding generated/randstruct_hash.h there adds it as build-dependency to
each object file.
Reported-by: Kees Cook <kees@kernel.org>
Closes: https://lore.kernel.org/linux-kbuild/202504161928.17A90D9B@keescook/
Signed-off-by: Nicolas Schier <n.schier@avm.de>
---
As I have no rust experience at all, yet: Do we have to consider
something for rust?
---
include/linux/compiler-version.h | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/include/linux/compiler-version.h b/include/linux/compiler-version.h
index 573fa85b6c0cd314dfeec66e8c77342798aa7e62..523eacf80c1a6149c513dccfd0dd9fd388e909a4 100644
--- a/include/linux/compiler-version.h
+++ b/include/linux/compiler-version.h
@@ -6,9 +6,19 @@
#define __LINUX_COMPILER_VERSION_H
/*
- * This header exists to force full rebuild when the compiler is upgraded.
+ * This header exists to force full rebuild when the compiler is upgraded or
+ * the randstruct is changed.
*
* When fixdep scans this, it will find this string "CONFIG_CC_VERSION_TEXT"
* and add dependency on include/config/CC_VERSION_TEXT, which is touched
* by Kconfig when the version string from the compiler changes.
*/
+#ifdef CONFIG_RANDSTRUCT
+/*
+ * If CONFIG_RANDSTRUCT is enabled and scripts/basic/randstruct.seed changes,
+ * randstruct_hash.h is updated. Including it here, makes it a build
+ * dependency for all build objects.
+ */
+#include <generated/randstruct_hash.h>
+#undef RANDSTRUCT_HASHED_SEED
+#endif
---
base-commit: 9c32cda43eb78f78c73aee4aa344b777714e259b
change-id: 20250429-rebuild-on-randstruct-seed-changes-6b45e327fb31
Best regards,
--
Nicolas Schier
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] randstruct: Rebuild completely if randstruct.seed changes
2025-04-29 12:59 [PATCH] randstruct: Rebuild completely if randstruct.seed changes Nicolas Schier
@ 2025-04-29 13:11 ` Miguel Ojeda
2025-04-29 16:52 ` Kees Cook
1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2025-04-29 13:11 UTC (permalink / raw)
To: Nicolas Schier
Cc: Kees Cook, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Masahiro Yamada, Nicolas Schier,
linux-hardening, linux-kbuild, linux-kernel, rust-for-linux
On Tue, Apr 29, 2025 at 2:59 PM Nicolas Schier <n.schier@avm.de> wrote:
>
> As I have no rust experience at all, yet: Do we have to consider
> something for rust?
It cannot be enabled yet together with Rust, so no worries, but I need
to remember to update this patch:
https://lore.kernel.org/rust-for-linux/20241119185747.862544-1-ojeda@kernel.org/
So I will reply there with a backlink to this.
I guess since we need to rebuild even `core`, I may need to add
something like the `fixdep` workaround we have to rebuild on
`RUSTC_VERSION_TEXT` changes.
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] randstruct: Rebuild completely if randstruct.seed changes
2025-04-29 12:59 [PATCH] randstruct: Rebuild completely if randstruct.seed changes Nicolas Schier
2025-04-29 13:11 ` Miguel Ojeda
@ 2025-04-29 16:52 ` Kees Cook
1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2025-04-29 16:52 UTC (permalink / raw)
To: Nicolas Schier
Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Masahiro Yamada, Nicolas Schier,
linux-hardening, linux-kbuild, linux-kernel, rust-for-linux
On Tue, Apr 29, 2025 at 02:59:13PM +0200, Nicolas Schier wrote:
> Include generated/randstruct_hash.h in linux/compiler-version.h to force
> a complete rebuild if CONFIG_RANDSTRUCT is enabled and randstruct.seed
> changes.
>
> Removal or change of scripts/basic/randstruct.seed leads to a remake of
> generated/randstruct_hash.h. As linux/compiler-version.h is a
> hard-coded include for every kbuild induced compilation, conditionally
> adding generated/randstruct_hash.h there adds it as build-dependency to
> each object file.
This does technically work, but this feels like the wrong solution.
Also, this won't work for another case where I need a similar thing: if
the .scl file for the integer sanitizer changes, we need to do the same
full rebuild, and that's not a C file.
I think we need to explicitly inject something into fixdep...
--
Kees Cook
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-29 16:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-29 12:59 [PATCH] randstruct: Rebuild completely if randstruct.seed changes Nicolas Schier
2025-04-29 13:11 ` Miguel Ojeda
2025-04-29 16:52 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox