hardening: Default randstruct off with rust for better allmodconfig support
Subsystems (3)
PATCH v2 1/1 hardening: Default randstruct off with rust for better allmodconfig support
Currently randstruct does not support rust so we have Kconfig dependencies which prevent rust being enabled when randstruct is. Unfortunately this prevents rust being enabled in allmodconfig, our standard coverage build. randstruct gets turned on by default, then the dependency on !RANDSTRUCT causes rust to get disabled.
Work around this by disabling randstruct by default if we have a usable rust toolchain and rust support for the architecture, circular dependencies prevent us directly depending on !RUST. This means we might end up with a configuration that disables both rust and randstruct but hopefully it's more likely go give the expected result.
---
Changes in v2:
- Add a HAVE_RUST in there too.
- Link to v1: https://patch.msgid.link/20260605-rust-reverse-randstruct-dep-v1-1-45ce9ee8d0d1@kernel.org
--- security/Kconfig.hardening | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/Kconfig.hardening +1 -1
@@ -285,7 +285,7 @@ config CC_HAS_RANDSTRUCT choice prompt "Randomize layout of sensitive kernel structures" - default RANDSTRUCT_FULL if COMPILE_TEST && (GCC_PLUGINS || CC_HAS_RANDSTRUCT) + default RANDSTRUCT_FULL if !(RUST_IS_AVAILABLE && HAVE_RUST) && COMPILE_TEST && (GCC_PLUGINS || CC_HAS_RANDSTRUCT) default RANDSTRUCT_NONE help If you enable this, the layouts of structures that are entirely
---
base-commit: e43ffb69e0438cddd72aaa30898b4dc446f664f8
change-id: 20260605-rust-reverse-randstruct-dep-5a504c861128
Best regards,
Signature · 1 line
Mark Brown <[email protected]>
Quoted 7 lines · Mark Brown
Currently randstruct does not support rust so we have
Kconfigdependencies which prevent rust being enabled when randstruct is. Unfortunately this prevents rust being enabled in allmodconfig, our standard coverage build. randstruct gets turned on by default, then the dependency on !RANDSTRUCT causes rust to get disabled.
Quoted 7 lines
Work around this by disabling randstruct by default if we have a usable rust toolchain and rust support for the architecture, circular dependencies prevent us directly depending on !RUST. This means we might end up with a configuration that disables both rust and randstruct but hopefully it's more likely go give the expected result.
Signed-off-by Mark Brown <[email protected]>
Thanks Mark!
Kees, Gustavo: applying this would help Mark's testing of Rust in linux-next, which is important to keep.
An alternative would be to move forward with RANDSTRUCT support:
https://lore.kernel.org/rust-for-linux/[email protected]/
Either the conditional (on the Rust side) or the unconditional approaches (modifying the C side) should be fine, i.e. whatever Kees/Gustavo think is best. The unconditional one would make things easier on the Rust side, but it is a "bigger" change in terms of impact. We can always start with the conditional one instead.
Cheers,
Miguel
Kees Cook
maintainerQuoted 23 lines · Miguel Ojeda
Quoted 7 lines · Mark Brown
Currently randstruct does not support rust so we have
Kconfigdependencies which prevent rust being enabled when randstruct is. Unfortunately this prevents rust being enabled in allmodconfig, our standard coverage build. randstruct gets turned on by default, then the dependency on !RANDSTRUCT causes rust to get disabled.Quoted 7 lines
Work around this by disabling randstruct by default if we have a usable rust toolchain and rust support for the architecture, circular dependencies prevent us directly depending on !RUST. This means we might end up with a configuration that disables both rust and randstruct but hopefully it's more likely go give the expected result.
Signed-off-by Mark Brown <[email protected]>Thanks Mark!
Kees, Gustavo: applying this would help Mark's testing of Rust in linux-next, which is important to keep.
An alternative would be to move forward with
RANDSTRUCTsupport:
Quoted 7 lines
https://lore.kernel.org/rust-for-linux/[email protected]/
Either the conditional (on the Rust side) or the unconditional approaches (modifying the C side) should be fine, i.e. whatever Kees/Gustavo think is best. The unconditional one would make things easier on the Rust side, but it is a "bigger" change in terms of impact. We can always start with the conditional one instead.
Oops, I missed this v2. :)
For the linux-next testing, are you doing GCC + llvm rustc builds? IIUC, then the support patch mentioned, I think, doesn't actually solve the problem?
-Kees
Signature · 1 line
Kees Cook
Quoted 3 lines · Kees Cook
For the linux-next testing, are you doing GCC + llvm rustc builds? IIUC, then the support patch mentioned, I think, doesn't actually solve the problem?
No, the allmodconfig builds are currently using LLVM - there's other issues with rust+GCC, right now KASAN IIRC, and it generally seems like it'll be more reliable to use LLVM to get the coverage. Both compilers need to work anyway.