* [PATCH 0/3] randstruct: gcc-plugin: Remove bogus void member
@ 2025-04-27 1:38 Kees Cook
2025-04-27 1:38 ` [PATCH 1/3] " Kees Cook
` (3 more replies)
0 siblings, 4 replies; 17+ messages in thread
From: Kees Cook @ 2025-04-27 1:38 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Kees Cook, Dr. David Alan Gilbert, Mark Brown, WangYuli,
Mickaël Salaün, Günther Noack, Bill Wendling,
Andrew Morton, Nathan Chancellor, Nick Desaulniers, Justin Stitt,
Petr Mladek, David Gow, Rae Moar, Tamir Duberstein, Diego Vieira,
Luis Chamberlain, Gustavo A. R. Silva, Paul Moore, James Morris,
Serge E. Hallyn, linux-kernel, llvm, linux-hardening,
linux-security-module
Hi,
Okay, I've tracked down the problem with the randstruct GCC plugin,
and written a KUnit test to validate behaviors. This lets us add
it back the COMPILE_TEST builds.
No need for https://lore.kernel.org/all/20250421000854.work.572-kees@kernel.org/
-Kees
Kees Cook (3):
randstruct: gcc-plugin: Remove bogus void member
lib/tests: Add randstruct KUnit test
Revert "hardening: Disable GCC randstruct for COMPILE_TEST"
MAINTAINERS | 1 +
lib/Kconfig.debug | 8 +
lib/tests/Makefile | 1 +
lib/tests/randstruct_kunit.c | 283 ++++++++++++++++++
scripts/gcc-plugins/randomize_layout_plugin.c | 18 +-
security/Kconfig.hardening | 2 +-
6 files changed, 295 insertions(+), 18 deletions(-)
create mode 100644 lib/tests/randstruct_kunit.c
--
2.34.1
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 1/3] randstruct: gcc-plugin: Remove bogus void member
2025-04-27 1:38 [PATCH 0/3] randstruct: gcc-plugin: Remove bogus void member Kees Cook
@ 2025-04-27 1:38 ` Kees Cook
2025-04-27 1:38 ` [PATCH 2/3] lib/tests: Add randstruct KUnit test Kees Cook
` (2 subsequent siblings)
3 siblings, 0 replies; 17+ messages in thread
From: Kees Cook @ 2025-04-27 1:38 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Kees Cook, Dr. David Alan Gilbert, Mark Brown, WangYuli,
Mickaël Salaün, Günther Noack, Bill Wendling,
Andrew Morton, Nathan Chancellor, Nick Desaulniers, Justin Stitt,
Petr Mladek, David Gow, Rae Moar, Tamir Duberstein, Diego Vieira,
Luis Chamberlain, Gustavo A. R. Silva, Paul Moore, James Morris,
Serge E. Hallyn, linux-kernel, llvm, linux-hardening,
linux-security-module
When building the randomized replacement tree of struct members, the
randstruct GCC plugin would insert, as the first member, a 0-sized void
member. This appears as though it was done to catch non-designated
("unnamed") static initializers, which wouldn't be stable since they
depend on the original struct layout order.
This was accomplished by having the side-effect of the "void member"
tripping an assert in GCC internals (count_type_elements) if the member
list ever needed to be counted (e.g. for figuring out the order of members
during a non-designated initialization), which would catch impossible type
(void) in the struct:
security/landlock/fs.c: In function ‘hook_file_ioctl_common’:
security/landlock/fs.c:1745:61: internal compiler error: in count_type_elements, at expr.cc:7075
1745 | .u.op = &(struct lsm_ioctlop_audit) {
| ^
static HOST_WIDE_INT
count_type_elements (const_tree type, bool for_ctor_p)
{
switch (TREE_CODE (type))
...
case VOID_TYPE:
default:
gcc_unreachable ();
}
}
However this is a redundant safety measure since randstruct uses the
__designated_initializer attribute both internally and within the
__randomized_layout attribute macro so that this would be enforced
by the compiler directly even when randstruct was not enabled (via
-Wdesignated-init).
A recent change in Landlock ended up tripping the same member counting
routine when using a full-struct copy initializer as part of an anonymous
initializer. This, however, is a false positive as the initializer is
copying between identical structs (and hence identical layouts). The
"path" member is "struct path", a randomized struct, and is being copied
to from another "struct path", the "f_path" member:
landlock_log_denial(landlock_cred(file->f_cred), &(struct landlock_request) {
.type = LANDLOCK_REQUEST_FS_ACCESS,
.audit = {
.type = LSM_AUDIT_DATA_IOCTL_OP,
.u.op = &(struct lsm_ioctlop_audit) {
.path = file->f_path,
.cmd = cmd,
},
},
...
As can be seen with the coming randstruct KUnit test, there appears to
be no behavioral problems with this kind of initialization when the void
member is removed from the randstruct GCC plugin, so remove it.
Reported-by: "Dr. David Alan Gilbert" <linux@treblig.org>
Closes: https://lore.kernel.org/lkml/Z_PRaKx7q70MKgCA@gallifrey/
Reported-by: Mark Brown <broonie@kernel.org>
Closes: https://lore.kernel.org/lkml/20250407-kbuild-disable-gcc-plugins-v1-1-5d46ae583f5e@kernel.org/
Reported-by: WangYuli <wangyuli@uniontech.com>
Closes: https://lore.kernel.org/lkml/337D5D4887277B27+3c677db3-a8b9-47f0-93a4-7809355f1381@uniontech.com/
Fixes: 313dd1b62921 ("gcc-plugins: Add the randstruct plugin")
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: "Mickaël Salaün" <mic@digikod.net>
Cc: Mark Brown <broonie@kernel.org>
Cc: "Günther Noack" <gnoack@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>
---
scripts/gcc-plugins/randomize_layout_plugin.c | 18 +-----------------
1 file changed, 1 insertion(+), 17 deletions(-)
diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c
index 5694df3da2e9..971a1908a8cc 100644
--- a/scripts/gcc-plugins/randomize_layout_plugin.c
+++ b/scripts/gcc-plugins/randomize_layout_plugin.c
@@ -344,29 +344,13 @@ static int relayout_struct(tree type)
shuffle(type, (tree *)newtree, shuffle_length);
- /*
- * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
- * as gcc provides no other way to detect such code
- */
- list = make_node(FIELD_DECL);
- TREE_CHAIN(list) = newtree[0];
- TREE_TYPE(list) = void_type_node;
- DECL_SIZE(list) = bitsize_zero_node;
- DECL_NONADDRESSABLE_P(list) = 1;
- DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
- DECL_SIZE_UNIT(list) = size_zero_node;
- DECL_FIELD_OFFSET(list) = size_zero_node;
- DECL_CONTEXT(list) = type;
- // to satisfy the constify plugin
- TREE_READONLY(list) = 1;
-
for (i = 0; i < num_fields - 1; i++)
TREE_CHAIN(newtree[i]) = newtree[i+1];
TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
main_variant = TYPE_MAIN_VARIANT(type);
for (variant = main_variant; variant; variant = TYPE_NEXT_VARIANT(variant)) {
- TYPE_FIELDS(variant) = list;
+ TYPE_FIELDS(variant) = newtree[0];
TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("designated_init"), NULL_TREE, TYPE_ATTRIBUTES(variant));
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 2/3] lib/tests: Add randstruct KUnit test
2025-04-27 1:38 [PATCH 0/3] randstruct: gcc-plugin: Remove bogus void member Kees Cook
2025-04-27 1:38 ` [PATCH 1/3] " Kees Cook
@ 2025-04-27 1:38 ` Kees Cook
2025-04-27 3:47 ` kernel test robot
` (3 more replies)
2025-04-27 1:38 ` [PATCH 3/3] Revert "hardening: Disable GCC randstruct for COMPILE_TEST" Kees Cook
2025-05-20 15:18 ` [PATCH 0/3] randstruct: gcc-plugin: Remove bogus void member Mickaël Salaün
3 siblings, 4 replies; 17+ messages in thread
From: Kees Cook @ 2025-04-27 1:38 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Kees Cook, Bill Wendling, Andrew Morton, Nathan Chancellor,
Nick Desaulniers, Justin Stitt, Petr Mladek, David Gow, Rae Moar,
Tamir Duberstein, Diego Vieira, Luis Chamberlain, llvm,
Dr. David Alan Gilbert, Mark Brown, WangYuli,
Mickaël Salaün, Günther Noack, Gustavo A. R. Silva,
Paul Moore, James Morris, Serge E. Hallyn, linux-kernel,
linux-hardening, linux-security-module
Perform basic validation about layout randomization and initialization
tracking when using CONFIG_RANDSTRUCT=y. Tested using:
$ ./tools/testing/kunit/kunit.py run \
--kconfig_add CONFIG_RANDSTRUCT_FULL=y \
randstruct
[17:22:30] ================= randstruct (2 subtests) ==================
[17:22:30] [PASSED] randstruct_layout
[17:22:30] [PASSED] randstruct_initializers
[17:22:30] =================== [PASSED] randstruct ====================
[17:22:30] ============================================================
[17:22:30] Testing complete. Ran 2 tests: passed: 2
[17:22:30] Elapsed time: 5.091s total, 0.001s configuring, 4.974s building, 0.086s running
Adding "--make_option LLVM=1" can be used to test Clang, which also
passes.
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Bill Wendling <morbo@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <nick.desaulniers+lkml@gmail.com>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Petr Mladek <pmladek@suse.com>
Cc: David Gow <davidgow@google.com>
Cc: Rae Moar <rmoar@google.com>
Cc: Tamir Duberstein <tamird@gmail.com>
Cc: Diego Vieira <diego.daniel.professional@gmail.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: <llvm@lists.linux.dev>
---
MAINTAINERS | 1 +
lib/Kconfig.debug | 8 +
lib/tests/Makefile | 1 +
lib/tests/randstruct_kunit.c | 283 +++++++++++++++++++++++++++++++++++
4 files changed, 293 insertions(+)
create mode 100644 lib/tests/randstruct_kunit.c
diff --git a/MAINTAINERS b/MAINTAINERS
index fa1e04e87d1d..aeb3e7911852 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12879,6 +12879,7 @@ F: include/linux/overflow.h
F: include/linux/randomize_kstack.h
F: include/linux/ucopysize.h
F: kernel/configs/hardening.config
+F: lib/tests/randstruct_kunit.c
F: lib/tests/usercopy_kunit.c
F: mm/usercopy.c
F: security/Kconfig.hardening
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index f9051ab610d5..6479cec900c7 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2863,6 +2863,14 @@ config OVERFLOW_KUNIT_TEST
If unsure, say N.
+config RANDSTRUCT_KUNIT_TEST
+ tristate "Test randstruct structure layout randomization at runtime" if !KUNIT_ALL_TESTS
+ depends on KUNIT
+ default KUNIT_ALL_TESTS
+ help
+ Builds unit tests for the checking CONFIG_RANDSTRUCT=y, which
+ randomizes structure layouts.
+
config STACKINIT_KUNIT_TEST
tristate "Test level of stack variable initialization" if !KUNIT_ALL_TESTS
depends on KUNIT
diff --git a/lib/tests/Makefile b/lib/tests/Makefile
index 5a4794c1826e..56d645014482 100644
--- a/lib/tests/Makefile
+++ b/lib/tests/Makefile
@@ -35,6 +35,7 @@ obj-$(CONFIG_MEMCPY_KUNIT_TEST) += memcpy_kunit.o
CFLAGS_overflow_kunit.o = $(call cc-disable-warning, tautological-constant-out-of-range-compare)
obj-$(CONFIG_OVERFLOW_KUNIT_TEST) += overflow_kunit.o
obj-$(CONFIG_PRINTF_KUNIT_TEST) += printf_kunit.o
+obj-$(CONFIG_RANDSTRUCT_KUNIT_TEST) += randstruct_kunit.o
obj-$(CONFIG_SCANF_KUNIT_TEST) += scanf_kunit.o
obj-$(CONFIG_SIPHASH_KUNIT_TEST) += siphash_kunit.o
obj-$(CONFIG_SLUB_KUNIT_TEST) += slub_kunit.o
diff --git a/lib/tests/randstruct_kunit.c b/lib/tests/randstruct_kunit.c
new file mode 100644
index 000000000000..6fc23dfa57b6
--- /dev/null
+++ b/lib/tests/randstruct_kunit.c
@@ -0,0 +1,283 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Test cases for struct randomization, i.e. CONFIG_RANDSTRUCT=y.
+ *
+ * For example, see:
+ * "Running tests with kunit_tool" at Documentation/dev-tools/kunit/start.rst
+ * ./tools/testing/kunit/kunit.py run randstruct [--raw_output] \
+ * [--make_option LLVM=1] \
+ * --kconfig_add CONFIG_RANDSTRUCT_FULL=y
+ *
+ */
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <kunit/test.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/string.h>
+
+#define DO_MANY_MEMBERS(macro, args...) \
+ macro(a, args) \
+ macro(b, args) \
+ macro(c, args) \
+ macro(d, args) \
+ macro(e, args) \
+ macro(f, args) \
+ macro(g, args) \
+ macro(h, args)
+
+#define do_enum(x, ignored) MEMBER_NAME_ ## x,
+enum randstruct_member_names {
+ DO_MANY_MEMBERS(do_enum)
+ MEMBER_NAME_MAX,
+};
+/* Make sure the macros are working: want 8 test members. */
+_Static_assert(MEMBER_NAME_MAX == 8);
+
+/* This is an unsigned long member to match the function pointer size */
+#define unsigned_long_member(x, ignored) unsigned long x;
+struct randstruct_untouched {
+ DO_MANY_MEMBERS(unsigned_long_member)
+};
+
+/* Struct explicitly marked with __randomize_layout. */
+struct randstruct_shuffled {
+ DO_MANY_MEMBERS(unsigned_long_member)
+} __randomize_layout;
+#undef unsigned_long_member
+
+/* Struct implicitly randomized from being all func ptrs. */
+#define func_member(x, ignored) size_t (*x)(int);
+struct randstruct_funcs_untouched {
+ DO_MANY_MEMBERS(func_member)
+} __no_randomize_layout;
+
+struct randstruct_funcs_shuffled {
+ DO_MANY_MEMBERS(func_member)
+};
+#undef func_member
+
+#define func_body(x, ignored) \
+static noinline size_t func_##x(int arg) \
+{ \
+ return offsetof(struct randstruct_funcs_untouched, x); \
+}
+DO_MANY_MEMBERS(func_body)
+
+/* Various mixed types. */
+#define mixed_members \
+ bool a; \
+ short b; \
+ unsigned int c __aligned(16); \
+ size_t d; \
+ char e; \
+ u64 f; \
+ union { \
+ struct randstruct_shuffled shuffled; \
+ uintptr_t g; \
+ }; \
+ union { \
+ void *ptr; \
+ char h; \
+ };
+
+struct randstruct_mixed_untouched {
+ mixed_members
+};
+
+struct randstruct_mixed_shuffled {
+ mixed_members
+} __randomize_layout;
+#undef mixed_members
+
+struct contains_randstruct_untouched {
+ int before;
+ struct randstruct_untouched untouched;
+ int after;
+};
+
+struct contains_randstruct_shuffled {
+ int before;
+ struct randstruct_shuffled shuffled;
+ int after;
+};
+
+static void randstruct_layout(struct kunit *test)
+{
+ int mismatches;
+
+#define check_mismatch(x, untouched, shuffled) \
+ if (offsetof(untouched, x) != offsetof(shuffled, x)) \
+ mismatches++; \
+ kunit_info(test, #shuffled "::" #x " @ %zu (vs %zu)\n", \
+ offsetof(shuffled, x), \
+ offsetof(untouched, x)); \
+
+#define check_pair(outcome, untouched, shuffled) \
+ mismatches = 0; \
+ DO_MANY_MEMBERS(check_mismatch, untouched, shuffled) \
+ kunit_info(test, "Differing " #untouched " vs " #shuffled " member positions: %d\n", \
+ mismatches); \
+ KUNIT_##outcome##_MSG(test, mismatches, 0, \
+ #untouched " vs " #shuffled " layouts: unlucky or broken?\n");
+
+ check_pair(EXPECT_EQ, struct randstruct_untouched, struct randstruct_untouched)
+ check_pair(EXPECT_GT, struct randstruct_untouched, struct randstruct_shuffled)
+ check_pair(EXPECT_GT, struct randstruct_untouched, struct randstruct_funcs_shuffled)
+ check_pair(EXPECT_GT, struct randstruct_funcs_untouched, struct randstruct_funcs_shuffled)
+ check_pair(EXPECT_GT, struct randstruct_mixed_untouched, struct randstruct_mixed_shuffled)
+#undef check_pair
+
+#undef check_mismatch
+}
+
+#define check_mismatch(x, ignore) \
+ KUNIT_EXPECT_EQ_MSG(test, untouched->x, shuffled->x, \
+ "Mismatched member value in %s initializer\n", \
+ name);
+
+static void test_check_init(struct kunit *test, const char *name,
+ struct randstruct_untouched *untouched,
+ struct randstruct_shuffled *shuffled)
+{
+ DO_MANY_MEMBERS(check_mismatch)
+}
+
+static void test_check_mixed_init(struct kunit *test, const char *name,
+ struct randstruct_mixed_untouched *untouched,
+ struct randstruct_mixed_shuffled *shuffled)
+{
+ DO_MANY_MEMBERS(check_mismatch)
+}
+#undef check_mismatch
+
+#define check_mismatch(x, ignore) \
+ KUNIT_EXPECT_EQ_MSG(test, untouched->untouched.x, \
+ shuffled->shuffled.x, \
+ "Mismatched member value in %s initializer\n", \
+ name);
+static void test_check_contained_init(struct kunit *test, const char *name,
+ struct contains_randstruct_untouched *untouched,
+ struct contains_randstruct_shuffled *shuffled)
+{
+ DO_MANY_MEMBERS(check_mismatch)
+}
+#undef check_mismatch
+
+#define check_mismatch(x, ignore) \
+ KUNIT_EXPECT_PTR_EQ_MSG(test, untouched->x, shuffled->x, \
+ "Mismatched member value in %s initializer\n", \
+ name);
+
+static void test_check_funcs_init(struct kunit *test, const char *name,
+ struct randstruct_funcs_untouched *untouched,
+ struct randstruct_funcs_shuffled *shuffled)
+{
+ DO_MANY_MEMBERS(check_mismatch)
+}
+#undef check_mismatch
+
+static void randstruct_initializers(struct kunit *test)
+{
+#define init_members \
+ .a = 1, \
+ .b = 3, \
+ .c = 5, \
+ .d = 7, \
+ .e = 11, \
+ .f = 13, \
+ .g = 17, \
+ .h = 19,
+ struct randstruct_untouched untouched = {
+ init_members
+ };
+ struct randstruct_shuffled shuffled = {
+ init_members
+ };
+ struct randstruct_mixed_untouched mixed_untouched = {
+ init_members
+ };
+ struct randstruct_mixed_shuffled mixed_shuffled = {
+ init_members
+ };
+ struct contains_randstruct_untouched contains_untouched = {
+ .untouched = {
+ init_members
+ },
+ };
+ struct contains_randstruct_shuffled contains_shuffled = {
+ .shuffled = {
+ init_members
+ },
+ };
+#define func_member(x, ignored) \
+ .x = func_##x,
+ struct randstruct_funcs_untouched funcs_untouched = {
+ DO_MANY_MEMBERS(func_member)
+ };
+ struct randstruct_funcs_shuffled funcs_shuffled = {
+ DO_MANY_MEMBERS(func_member)
+ };
+
+ test_check_init(test, "named", &untouched, &shuffled);
+ test_check_init(test, "unnamed", &untouched,
+ &(struct randstruct_shuffled){
+ init_members
+ });
+
+ test_check_contained_init(test, "named", &contains_untouched, &contains_shuffled);
+ test_check_contained_init(test, "unnamed", &contains_untouched,
+ &(struct contains_randstruct_shuffled){
+ .shuffled = (struct randstruct_shuffled){
+ init_members
+ },
+ });
+
+ test_check_contained_init(test, "named", &contains_untouched, &contains_shuffled);
+ test_check_contained_init(test, "unnamed copy", &contains_untouched,
+ &(struct contains_randstruct_shuffled){
+ /* full struct copy initializer */
+ .shuffled = shuffled,
+ });
+
+ test_check_mixed_init(test, "named", &mixed_untouched, &mixed_shuffled);
+ test_check_mixed_init(test, "unnamed", &mixed_untouched,
+ &(struct randstruct_mixed_shuffled){
+ init_members
+ });
+
+ test_check_funcs_init(test, "named", &funcs_untouched, &funcs_shuffled);
+ test_check_funcs_init(test, "unnamed", &funcs_untouched,
+ &(struct randstruct_funcs_shuffled){
+ DO_MANY_MEMBERS(func_member)
+ });
+
+#undef func_member
+#undef init_members
+}
+
+static int randstruct_test_init(struct kunit *test)
+{
+ if (!IS_ENABLED(CONFIG_RANDSTRUCT))
+ kunit_skip(test, "Not built with CONFIG_RANDSTRUCT=y");
+
+ return 0;
+}
+
+static struct kunit_case randstruct_test_cases[] = {
+ KUNIT_CASE(randstruct_layout),
+ KUNIT_CASE(randstruct_initializers),
+ {}
+};
+
+static struct kunit_suite randstruct_test_suite = {
+ .name = "randstruct",
+ .init = randstruct_test_init,
+ .test_cases = randstruct_test_cases,
+};
+
+kunit_test_suites(&randstruct_test_suite);
+
+MODULE_DESCRIPTION("Test cases for struct randomization");
+MODULE_LICENSE("GPL");
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 3/3] Revert "hardening: Disable GCC randstruct for COMPILE_TEST"
2025-04-27 1:38 [PATCH 0/3] randstruct: gcc-plugin: Remove bogus void member Kees Cook
2025-04-27 1:38 ` [PATCH 1/3] " Kees Cook
2025-04-27 1:38 ` [PATCH 2/3] lib/tests: Add randstruct KUnit test Kees Cook
@ 2025-04-27 1:38 ` Kees Cook
2025-05-30 0:06 ` Thiago Jung Bauermann
2025-05-20 15:18 ` [PATCH 0/3] randstruct: gcc-plugin: Remove bogus void member Mickaël Salaün
3 siblings, 1 reply; 17+ messages in thread
From: Kees Cook @ 2025-04-27 1:38 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Kees Cook, Dr. David Alan Gilbert, Mark Brown, WangYuli,
Mickaël Salaün, Günther Noack, Bill Wendling,
Andrew Morton, Nathan Chancellor, Nick Desaulniers, Justin Stitt,
Petr Mladek, David Gow, Rae Moar, Tamir Duberstein, Diego Vieira,
Luis Chamberlain, Gustavo A. R. Silva, Paul Moore, James Morris,
Serge E. Hallyn, linux-kernel, llvm, linux-hardening,
linux-security-module
This reverts commit f5c68a4e84f9feca3be578199ec648b676db2030.
It is again possible to build "allmodconfig" with the randstruct GCC
plugin, so enable it for COMPILE_TEST to catch future bugs.
Signed-off-by: Kees Cook <kees@kernel.org>
---
security/Kconfig.hardening | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening
index 3fe9d7b945c4..c17366ce8224 100644
--- a/security/Kconfig.hardening
+++ b/security/Kconfig.hardening
@@ -344,7 +344,7 @@ config CC_HAS_RANDSTRUCT
choice
prompt "Randomize layout of sensitive kernel structures"
- default RANDSTRUCT_FULL if COMPILE_TEST && CC_HAS_RANDSTRUCT
+ default RANDSTRUCT_FULL if COMPILE_TEST && (GCC_PLUGINS || CC_HAS_RANDSTRUCT)
default RANDSTRUCT_NONE
help
If you enable this, the layouts of structures that are entirely
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH 2/3] lib/tests: Add randstruct KUnit test
2025-04-27 1:38 ` [PATCH 2/3] lib/tests: Add randstruct KUnit test Kees Cook
@ 2025-04-27 3:47 ` kernel test robot
2025-04-27 3:47 ` kernel test robot
` (2 subsequent siblings)
3 siblings, 0 replies; 17+ messages in thread
From: kernel test robot @ 2025-04-27 3:47 UTC (permalink / raw)
To: Kees Cook, Arnd Bergmann
Cc: oe-kbuild-all, Kees Cook, Bill Wendling, Andrew Morton,
Linux Memory Management List, Nathan Chancellor, Nick Desaulniers,
Justin Stitt, Petr Mladek, David Gow, Rae Moar, Tamir Duberstein,
Diego Vieira, Luis Chamberlain, llvm, Dr. David Alan Gilbert,
Mark Brown, WangYuli, Mickaël Salaün,
Günther Noack, Gustavo A. R. Silva, Paul Moore, James Morris,
Serge E. Hallyn, linux-kernel, linux-hardening,
linux-security-module
Hi Kees,
kernel test robot noticed the following build errors:
[auto build test ERROR on kees/for-next/hardening]
[also build test ERROR on linus/master v6.15-rc3 next-20250424]
[cannot apply to akpm-mm/mm-nonmm-unstable soc/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Kees-Cook/randstruct-gcc-plugin-Remove-bogus-void-member/20250427-093946
base: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening
patch link: https://lore.kernel.org/r/20250427013836.877214-2-kees%40kernel.org
patch subject: [PATCH 2/3] lib/tests: Add randstruct KUnit test
config: s390-randconfig-002-20250427 (https://download.01.org/0day-ci/archive/20250427/202504271124.gDNKq7ZN-lkp@intel.com/config)
compiler: s390-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250427/202504271124.gDNKq7ZN-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504271124.gDNKq7ZN-lkp@intel.com/
All errors (new ones prefixed by >>):
>> lib/tests/randstruct_kunit.c:36:36: error: expected ',' before ')' token
_Static_assert(MEMBER_NAME_MAX == 8);
^
,
cc1: warning: unrecognized command line option '-Wno-unterminated-string-initialization'
vim +36 lib/tests/randstruct_kunit.c
19
20 #define DO_MANY_MEMBERS(macro, args...) \
21 macro(a, args) \
22 macro(b, args) \
23 macro(c, args) \
24 macro(d, args) \
25 macro(e, args) \
26 macro(f, args) \
27 macro(g, args) \
28 macro(h, args)
29
30 #define do_enum(x, ignored) MEMBER_NAME_ ## x,
31 enum randstruct_member_names {
32 DO_MANY_MEMBERS(do_enum)
33 MEMBER_NAME_MAX,
34 };
35 /* Make sure the macros are working: want 8 test members. */
> 36 _Static_assert(MEMBER_NAME_MAX == 8);
37
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/3] lib/tests: Add randstruct KUnit test
2025-04-27 1:38 ` [PATCH 2/3] lib/tests: Add randstruct KUnit test Kees Cook
2025-04-27 3:47 ` kernel test robot
@ 2025-04-27 3:47 ` kernel test robot
2025-04-30 18:56 ` Kees Cook
2025-04-27 6:04 ` kernel test robot
2025-04-29 7:44 ` David Gow
3 siblings, 1 reply; 17+ messages in thread
From: kernel test robot @ 2025-04-27 3:47 UTC (permalink / raw)
To: Kees Cook, Arnd Bergmann
Cc: llvm, oe-kbuild-all, Kees Cook, Bill Wendling, Andrew Morton,
Linux Memory Management List, Nathan Chancellor, Nick Desaulniers,
Justin Stitt, Petr Mladek, David Gow, Rae Moar, Tamir Duberstein,
Diego Vieira, Luis Chamberlain, Dr. David Alan Gilbert,
Mark Brown, WangYuli, Mickaël Salaün,
Günther Noack, Gustavo A. R. Silva, Paul Moore, James Morris,
Serge E. Hallyn, linux-kernel, linux-hardening,
linux-security-module
Hi Kees,
kernel test robot noticed the following build warnings:
[auto build test WARNING on kees/for-next/hardening]
[also build test WARNING on linus/master v6.15-rc3 next-20250424]
[cannot apply to akpm-mm/mm-nonmm-unstable soc/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Kees-Cook/randstruct-gcc-plugin-Remove-bogus-void-member/20250427-093946
base: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening
patch link: https://lore.kernel.org/r/20250427013836.877214-2-kees%40kernel.org
patch subject: [PATCH 2/3] lib/tests: Add randstruct KUnit test
config: riscv-randconfig-001-20250427 (https://download.01.org/0day-ci/archive/20250427/202504271150.Be642Srg-lkp@intel.com/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250427/202504271150.Be642Srg-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504271150.Be642Srg-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> lib/tests/randstruct_kunit.c:36:36: warning: '_Static_assert' with no message is a C23 extension [-Wc23-extensions]
36 | _Static_assert(MEMBER_NAME_MAX == 8);
| ^
| , ""
1 warning generated.
vim +/_Static_assert +36 lib/tests/randstruct_kunit.c
19
20 #define DO_MANY_MEMBERS(macro, args...) \
21 macro(a, args) \
22 macro(b, args) \
23 macro(c, args) \
24 macro(d, args) \
25 macro(e, args) \
26 macro(f, args) \
27 macro(g, args) \
28 macro(h, args)
29
30 #define do_enum(x, ignored) MEMBER_NAME_ ## x,
31 enum randstruct_member_names {
32 DO_MANY_MEMBERS(do_enum)
33 MEMBER_NAME_MAX,
34 };
35 /* Make sure the macros are working: want 8 test members. */
> 36 _Static_assert(MEMBER_NAME_MAX == 8);
37
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/3] lib/tests: Add randstruct KUnit test
2025-04-27 1:38 ` [PATCH 2/3] lib/tests: Add randstruct KUnit test Kees Cook
2025-04-27 3:47 ` kernel test robot
2025-04-27 3:47 ` kernel test robot
@ 2025-04-27 6:04 ` kernel test robot
2025-04-29 7:44 ` David Gow
3 siblings, 0 replies; 17+ messages in thread
From: kernel test robot @ 2025-04-27 6:04 UTC (permalink / raw)
To: Kees Cook, Arnd Bergmann
Cc: llvm, oe-kbuild-all, Kees Cook, Bill Wendling, Andrew Morton,
Linux Memory Management List, Nathan Chancellor, Nick Desaulniers,
Justin Stitt, Petr Mladek, David Gow, Rae Moar, Tamir Duberstein,
Diego Vieira, Luis Chamberlain, Dr. David Alan Gilbert,
Mark Brown, WangYuli, Mickaël Salaün,
Günther Noack, Gustavo A. R. Silva, Paul Moore, James Morris,
Serge E. Hallyn, linux-kernel, linux-hardening,
linux-security-module
Hi Kees,
kernel test robot noticed the following build warnings:
[auto build test WARNING on kees/for-next/hardening]
[also build test WARNING on linus/master v6.15-rc3 next-20250424]
[cannot apply to akpm-mm/mm-nonmm-unstable soc/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Kees-Cook/randstruct-gcc-plugin-Remove-bogus-void-member/20250427-093946
base: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening
patch link: https://lore.kernel.org/r/20250427013836.877214-2-kees%40kernel.org
patch subject: [PATCH 2/3] lib/tests: Add randstruct KUnit test
config: powerpc64-randconfig-002-20250427 (https://download.01.org/0day-ci/archive/20250427/202504271552.T3fbs0XC-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250427/202504271552.T3fbs0XC-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504271552.T3fbs0XC-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> lib/tests/randstruct_kunit.c:36:36: warning: '_Static_assert' with no message is a C2x extension [-Wc2x-extensions]
36 | _Static_assert(MEMBER_NAME_MAX == 8);
| ^
| , ""
1 warning generated.
vim +/_Static_assert +36 lib/tests/randstruct_kunit.c
19
20 #define DO_MANY_MEMBERS(macro, args...) \
21 macro(a, args) \
22 macro(b, args) \
23 macro(c, args) \
24 macro(d, args) \
25 macro(e, args) \
26 macro(f, args) \
27 macro(g, args) \
28 macro(h, args)
29
30 #define do_enum(x, ignored) MEMBER_NAME_ ## x,
31 enum randstruct_member_names {
32 DO_MANY_MEMBERS(do_enum)
33 MEMBER_NAME_MAX,
34 };
35 /* Make sure the macros are working: want 8 test members. */
> 36 _Static_assert(MEMBER_NAME_MAX == 8);
37
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/3] lib/tests: Add randstruct KUnit test
2025-04-27 1:38 ` [PATCH 2/3] lib/tests: Add randstruct KUnit test Kees Cook
` (2 preceding siblings ...)
2025-04-27 6:04 ` kernel test robot
@ 2025-04-29 7:44 ` David Gow
2025-04-30 18:56 ` Kees Cook
3 siblings, 1 reply; 17+ messages in thread
From: David Gow @ 2025-04-29 7:44 UTC (permalink / raw)
To: Kees Cook
Cc: Arnd Bergmann, Bill Wendling, Andrew Morton, Nathan Chancellor,
Nick Desaulniers, Justin Stitt, Petr Mladek, Rae Moar,
Tamir Duberstein, Diego Vieira, Luis Chamberlain, llvm,
Dr. David Alan Gilbert, Mark Brown, WangYuli,
Mickaël Salaün, Günther Noack, Gustavo A. R. Silva,
Paul Moore, James Morris, Serge E. Hallyn, linux-kernel,
linux-hardening, linux-security-module
[-- Attachment #1: Type: text/plain, Size: 1191 bytes --]
On Sun, 27 Apr 2025 at 09:38, Kees Cook <kees@kernel.org> wrote:
>
> Perform basic validation about layout randomization and initialization
> tracking when using CONFIG_RANDSTRUCT=y. Tested using:
>
> $ ./tools/testing/kunit/kunit.py run \
> --kconfig_add CONFIG_RANDSTRUCT_FULL=y \
> randstruct
> [17:22:30] ================= randstruct (2 subtests) ==================
> [17:22:30] [PASSED] randstruct_layout
> [17:22:30] [PASSED] randstruct_initializers
> [17:22:30] =================== [PASSED] randstruct ====================
> [17:22:30] ============================================================
> [17:22:30] Testing complete. Ran 2 tests: passed: 2
> [17:22:30] Elapsed time: 5.091s total, 0.001s configuring, 4.974s building, 0.086s running
>
> Adding "--make_option LLVM=1" can be used to test Clang, which also
> passes.
>
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
This works here for me. I'm a little wary of the prospect of the
"unlucky or broken" message making the test fail if we're just
unlucky, but it seems unlikely enough that we can deal with it later
if it ever becomes a problem.
Acked-by: David Gow <davidgow@google.com>
Cheers,
-- David
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5281 bytes --]
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/3] lib/tests: Add randstruct KUnit test
2025-04-29 7:44 ` David Gow
@ 2025-04-30 18:56 ` Kees Cook
0 siblings, 0 replies; 17+ messages in thread
From: Kees Cook @ 2025-04-30 18:56 UTC (permalink / raw)
To: David Gow
Cc: Arnd Bergmann, Bill Wendling, Andrew Morton, Nathan Chancellor,
Nick Desaulniers, Justin Stitt, Petr Mladek, Rae Moar,
Tamir Duberstein, Diego Vieira, Luis Chamberlain, llvm,
Dr. David Alan Gilbert, Mark Brown, WangYuli,
Mickaël Salaün, Günther Noack, Gustavo A. R. Silva,
Paul Moore, James Morris, Serge E. Hallyn, linux-kernel,
linux-hardening, linux-security-module
On Tue, Apr 29, 2025 at 03:44:01PM +0800, David Gow wrote:
> On Sun, 27 Apr 2025 at 09:38, Kees Cook <kees@kernel.org> wrote:
> >
> > Perform basic validation about layout randomization and initialization
> > tracking when using CONFIG_RANDSTRUCT=y. Tested using:
> >
> > $ ./tools/testing/kunit/kunit.py run \
> > --kconfig_add CONFIG_RANDSTRUCT_FULL=y \
> > randstruct
> > [17:22:30] ================= randstruct (2 subtests) ==================
> > [17:22:30] [PASSED] randstruct_layout
> > [17:22:30] [PASSED] randstruct_initializers
> > [17:22:30] =================== [PASSED] randstruct ====================
> > [17:22:30] ============================================================
> > [17:22:30] Testing complete. Ran 2 tests: passed: 2
> > [17:22:30] Elapsed time: 5.091s total, 0.001s configuring, 4.974s building, 0.086s running
> >
> > Adding "--make_option LLVM=1" can be used to test Clang, which also
> > passes.
> >
> > Signed-off-by: Kees Cook <kees@kernel.org>
> > ---
>
> This works here for me. I'm a little wary of the prospect of the
> "unlucky or broken" message making the test fail if we're just
> unlucky, but it seems unlikely enough that we can deal with it later
> if it ever becomes a problem.
>
> Acked-by: David Gow <davidgow@google.com>
Thanks!
Yeah, I wonder if it might be an interesting adjustment to the shuffling
to make sure it isn't a no-op? Like, it would shuffle with the original
hash, and if it's a no-op, it could permute the hash again, and then try
again? Hmmm...
--
Kees Cook
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/3] lib/tests: Add randstruct KUnit test
2025-04-27 3:47 ` kernel test robot
@ 2025-04-30 18:56 ` Kees Cook
0 siblings, 0 replies; 17+ messages in thread
From: Kees Cook @ 2025-04-30 18:56 UTC (permalink / raw)
To: kernel test robot
Cc: Arnd Bergmann, llvm, oe-kbuild-all, Bill Wendling, Andrew Morton,
Linux Memory Management List, Nathan Chancellor, Nick Desaulniers,
Justin Stitt, Petr Mladek, David Gow, Rae Moar, Tamir Duberstein,
Diego Vieira, Luis Chamberlain, Dr. David Alan Gilbert,
Mark Brown, WangYuli, Mickaël Salaün,
Günther Noack, Gustavo A. R. Silva, Paul Moore, James Morris,
Serge E. Hallyn, linux-kernel, linux-hardening,
linux-security-module
On Sun, Apr 27, 2025 at 11:47:19AM +0800, kernel test robot wrote:
> Hi Kees,
>
> kernel test robot noticed the following build warnings:
>
> [auto build test WARNING on kees/for-next/hardening]
> [also build test WARNING on linus/master v6.15-rc3 next-20250424]
> [cannot apply to akpm-mm/mm-nonmm-unstable soc/for-next]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url: https://github.com/intel-lab-lkp/linux/commits/Kees-Cook/randstruct-gcc-plugin-Remove-bogus-void-member/20250427-093946
> base: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening
> patch link: https://lore.kernel.org/r/20250427013836.877214-2-kees%40kernel.org
> patch subject: [PATCH 2/3] lib/tests: Add randstruct KUnit test
> config: riscv-randconfig-001-20250427 (https://download.01.org/0day-ci/archive/20250427/202504271150.Be642Srg-lkp@intel.com/config)
> compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250427/202504271150.Be642Srg-lkp@intel.com/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202504271150.Be642Srg-lkp@intel.com/
>
> All warnings (new ones prefixed by >>):
>
> >> lib/tests/randstruct_kunit.c:36:36: warning: '_Static_assert' with no message is a C23 extension [-Wc23-extensions]
> 36 | _Static_assert(MEMBER_NAME_MAX == 8);
> | ^
> | , ""
> 1 warning generated.
Thanks! I've fixed this locally.
--
Kees Cook
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 0/3] randstruct: gcc-plugin: Remove bogus void member
2025-04-27 1:38 [PATCH 0/3] randstruct: gcc-plugin: Remove bogus void member Kees Cook
` (2 preceding siblings ...)
2025-04-27 1:38 ` [PATCH 3/3] Revert "hardening: Disable GCC randstruct for COMPILE_TEST" Kees Cook
@ 2025-05-20 15:18 ` Mickaël Salaün
2025-05-20 16:14 ` Kees Cook
3 siblings, 1 reply; 17+ messages in thread
From: Mickaël Salaün @ 2025-05-20 15:18 UTC (permalink / raw)
To: Kees Cook
Cc: Arnd Bergmann, Dr. David Alan Gilbert, Mark Brown, WangYuli,
Günther Noack, Bill Wendling, Andrew Morton,
Nathan Chancellor, Nick Desaulniers, Justin Stitt, Petr Mladek,
David Gow, Rae Moar, Tamir Duberstein, Diego Vieira,
Luis Chamberlain, Gustavo A. R. Silva, Paul Moore, James Morris,
Serge E. Hallyn, linux-kernel, llvm, linux-hardening,
linux-security-module
On Sat, Apr 26, 2025 at 06:38:32PM -0700, Kees Cook wrote:
> Hi,
>
> Okay, I've tracked down the problem with the randstruct GCC plugin,
> and written a KUnit test to validate behaviors. This lets us add
> it back the COMPILE_TEST builds.
>
> No need for https://lore.kernel.org/all/20250421000854.work.572-kees@kernel.org/
Hi,
What is the status of this patch series? Do you plan to send it for
v6.15?
>
> -Kees
>
> Kees Cook (3):
> randstruct: gcc-plugin: Remove bogus void member
> lib/tests: Add randstruct KUnit test
> Revert "hardening: Disable GCC randstruct for COMPILE_TEST"
>
> MAINTAINERS | 1 +
> lib/Kconfig.debug | 8 +
> lib/tests/Makefile | 1 +
> lib/tests/randstruct_kunit.c | 283 ++++++++++++++++++
> scripts/gcc-plugins/randomize_layout_plugin.c | 18 +-
> security/Kconfig.hardening | 2 +-
> 6 files changed, 295 insertions(+), 18 deletions(-)
> create mode 100644 lib/tests/randstruct_kunit.c
>
> --
> 2.34.1
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 0/3] randstruct: gcc-plugin: Remove bogus void member
2025-05-20 15:18 ` [PATCH 0/3] randstruct: gcc-plugin: Remove bogus void member Mickaël Salaün
@ 2025-05-20 16:14 ` Kees Cook
0 siblings, 0 replies; 17+ messages in thread
From: Kees Cook @ 2025-05-20 16:14 UTC (permalink / raw)
To: Mickaël Salaün
Cc: Arnd Bergmann, Dr. David Alan Gilbert, Mark Brown, WangYuli,
Günther Noack, Bill Wendling, Andrew Morton,
Nathan Chancellor, Nick Desaulniers, Justin Stitt, Petr Mladek,
David Gow, Rae Moar, Tamir Duberstein, Diego Vieira,
Luis Chamberlain, Gustavo A. R. Silva, Paul Moore, James Morris,
Serge E. Hallyn, linux-kernel, llvm, linux-hardening,
linux-security-module
On Tue, May 20, 2025 at 05:18:56PM +0200, Mickaël Salaün wrote:
> On Sat, Apr 26, 2025 at 06:38:32PM -0700, Kees Cook wrote:
> > Hi,
> >
> > Okay, I've tracked down the problem with the randstruct GCC plugin,
> > and written a KUnit test to validate behaviors. This lets us add
> > it back the COMPILE_TEST builds.
> >
> > No need for https://lore.kernel.org/all/20250421000854.work.572-kees@kernel.org/
>
> Hi,
>
> What is the status of this patch series? Do you plan to send it for
> v6.15?
Since it is pretty late for v6.15 and exposes missed designated
initializers, I was planning to send it (and the designated initializer
fixes) for the v6.16 merge window and have them all go into -stable
for v6.15.
--
Kees Cook
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/3] Revert "hardening: Disable GCC randstruct for COMPILE_TEST"
2025-04-27 1:38 ` [PATCH 3/3] Revert "hardening: Disable GCC randstruct for COMPILE_TEST" Kees Cook
@ 2025-05-30 0:06 ` Thiago Jung Bauermann
2025-05-30 5:12 ` Kees Cook
0 siblings, 1 reply; 17+ messages in thread
From: Thiago Jung Bauermann @ 2025-05-30 0:06 UTC (permalink / raw)
To: kees
Cc: akpm, arnd, broonie, davidgow, diego.daniel.professional, gnoack,
gustavoars, jmorris, justinstitt, linux-hardening, linux-kernel,
linux-security-module, linux, llvm, mcgrof, mic, morbo, nathan,
nick.desaulniers+lkml, paul, pmladek, rmoar, serge, tamird,
wangyuli
Hello,
This commit was reported by our CI as breaking the allmodconfig build for
the arm and arm64 architectures when using GCC 15. This is due to
https://github.com/KSPP/linux/issues/367 :
-00:05:08 *** WARNING *** there are active plugins, do not report this as a bug unless you can reproduce it without enabling any plugins.
00:05:08 Event | Plugins
00:05:08 PLUGIN_FINISH_TYPE | randomize_layout_plugin
00:05:08 PLUGIN_FINISH_DECL | randomize_layout_plugin
00:05:08 PLUGIN_ATTRIBUTES | latent_entropy_plugin randomize_layout_plugin
00:05:08 PLUGIN_START_UNIT | latent_entropy_plugin stackleak_plugin
00:05:08 PLUGIN_ALL_IPA_PASSES_START | randomize_layout_plugin
00:05:08 arch/arm64/kernel/kexec_image.c:132:14: internal compiler error: in comptypes_check_enum_int, at c/c-typeck.cc:1519
00:05:08 132 | const struct kexec_file_ops kexec_image_ops = {
00:05:08 | ^~~~~~~~~~~~~~
00:05:08 0x225bdff internal_error(char const*, ...)
00:05:08 ../../../../../../gcc/gcc/diagnostic-global-context.cc:517
00:05:08 0x7cb197 fancy_abort(char const*, int, char const*)
00:05:08 ../../../../../../gcc/gcc/diagnostic.cc:1803
00:05:08 0x81f0e7 comptypes_check_enum_int(tree_node*, tree_node*, bool*)
00:05:08 ../../../../../../gcc/gcc/c/c-typeck.cc:1519
00:05:08 0x81f0e7 comptypes_check_enum_int(tree_node*, tree_node*, bool*)
00:05:08 ../../../../../../gcc/gcc/c/c-typeck.cc:1513
00:05:08 0x7e3b83 diagnose_mismatched_decls
00:05:08 ../../../../../../gcc/gcc/c/c-decl.cc:2170
00:05:08 0x7e64f3 duplicate_decls
00:05:08 ../../../../../../gcc/gcc/c/c-decl.cc:3169
00:05:08 0x7ea1eb pushdecl(tree_node*)
00:05:08 ../../../../../../gcc/gcc/c/c-decl.cc:3376
00:05:08 0x803c03 start_decl(c_declarator*, c_declspecs*, bool, tree_node*, bool, unsigned long*)
00:05:08 ../../../../../../gcc/gcc/c/c-decl.cc:5755
00:05:08 0x864c67 c_parser_declaration_or_fndef
00:05:08 ../../../../../../gcc/gcc/c/c-parser.cc:2851
00:05:08 0x8a7b33 c_parser_external_declaration
00:05:08 ../../../../../../gcc/gcc/c/c-parser.cc:2110
00:05:08 0x8a8ba3 c_parser_translation_unit
00:05:08 ../../../../../../gcc/gcc/c/c-parser.cc:1964
00:05:08 0x8a8ba3 c_parse_file()
00:05:08 ../../../../../../gcc/gcc/c/c-parser.cc:29839
00:05:08 0x931eff c_common_parse_file()
00:05:08 ../../../../../../gcc/gcc/c-family/c-opts.cc:1385
00:05:08 Please submit a full bug report, with preprocessed source (by using -freport-bug).
00:05:08 Please include the complete backtrace with any bug report.
00:05:08 See <https://gcc.gnu.org/bugs/> for instructions.
00:05:08 make[4]: *** [scripts/Makefile.build:203: arch/arm64/kernel/kexec_image.o] Error 1
The same error repeats for several other source files.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/3] Revert "hardening: Disable GCC randstruct for COMPILE_TEST"
2025-05-30 0:06 ` Thiago Jung Bauermann
@ 2025-05-30 5:12 ` Kees Cook
2025-05-30 19:09 ` Nathan Chancellor
0 siblings, 1 reply; 17+ messages in thread
From: Kees Cook @ 2025-05-30 5:12 UTC (permalink / raw)
To: Thiago Jung Bauermann
Cc: akpm, arnd, broonie, davidgow, diego.daniel.professional, gnoack,
gustavoars, jmorris, justinstitt, linux-hardening, linux-kernel,
linux-security-module, linux, llvm, mcgrof, mic, morbo, nathan,
nick.desaulniers+lkml, paul, pmladek, rmoar, serge, tamird,
wangyuli
On Thu, May 29, 2025 at 09:06:46PM -0300, Thiago Jung Bauermann wrote:
> This commit was reported by our CI as breaking the allmodconfig build for
> the arm and arm64 architectures when using GCC 15. This is due to
> https://github.com/KSPP/linux/issues/367 :
>
> 00:05:08 arch/arm64/kernel/kexec_image.c:132:14: internal compiler error: in comptypes_check_enum_int, at c/c-typeck.cc:1519
> 00:05:08 132 | const struct kexec_file_ops kexec_image_ops = {
> 00:05:08 | ^~~~~~~~~~~~~~
I'm not able to reproduce this. Which specific version of GCC 15 and
on what distro are you seeing this?
This is Fedora 42 for me:
$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (GCC) 15.1.1 20250425 (Red Hat Cross 15.1.1-1)
...
$ make O=gcc-arm64 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- allmodconfig
$ grep RANDSTRUCT gcc-arm64/.config
# CONFIG_RANDSTRUCT_NONE is not set
CONFIG_RANDSTRUCT_FULL=y
# CONFIG_RANDSTRUCT_PERFORMANCE is not set
CONFIG_RANDSTRUCT=y
CONFIG_GCC_PLUGIN_RANDSTRUCT=y
CONFIG_RANDSTRUCT_KUNIT_TEST=m
$ make O=gcc-arm64 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- all -s
$ file gcc-arm64/vmlinux
gcc-arm64/vmlinux: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), statically linked, BuildID[sha1]=b53656cb73bb82f4e19edbfa54241c203daa3fed, not stripped
And the new KUnit randstruct selftests all pass as well:
$ ./tools/testing/kunit/kunit.py run \
--arch arm64 --cross_compile aarch64-linux-gnu- \
--kconfig_add CONFIG_RANDSTRUCT_FULL=y randstruct
...
# Totals: pass:5 fail:0 skip:0 total:5
--
Kees Cook
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/3] Revert "hardening: Disable GCC randstruct for COMPILE_TEST"
2025-05-30 5:12 ` Kees Cook
@ 2025-05-30 19:09 ` Nathan Chancellor
2025-05-30 19:37 ` Kees Cook
2025-05-30 22:31 ` Kees Cook
0 siblings, 2 replies; 17+ messages in thread
From: Nathan Chancellor @ 2025-05-30 19:09 UTC (permalink / raw)
To: Kees Cook
Cc: Thiago Jung Bauermann, akpm, arnd, broonie, davidgow,
diego.daniel.professional, gnoack, gustavoars, jmorris,
justinstitt, linux-hardening, linux-kernel, linux-security-module,
linux, llvm, mcgrof, mic, morbo, nick.desaulniers+lkml, paul,
pmladek, rmoar, serge, tamird, wangyuli
On Thu, May 29, 2025 at 10:12:22PM -0700, Kees Cook wrote:
> On Thu, May 29, 2025 at 09:06:46PM -0300, Thiago Jung Bauermann wrote:
> > This commit was reported by our CI as breaking the allmodconfig build for
> > the arm and arm64 architectures when using GCC 15. This is due to
> > https://github.com/KSPP/linux/issues/367 :
> >
> > 00:05:08 arch/arm64/kernel/kexec_image.c:132:14: internal compiler error: in comptypes_check_enum_int, at c/c-typeck.cc:1519
> > 00:05:08 132 | const struct kexec_file_ops kexec_image_ops = {
> > 00:05:08 | ^~~~~~~~~~~~~~
>
> I'm not able to reproduce this. Which specific version of GCC 15 and
> on what distro are you seeing this?
It looks like this was also reported to Debian (I originally noticed it
in the #gcc channel on OFTC a couple of weeks ago but forgot to mention
it):
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1104745
It looks like the difference might be whether GCC was built with
additional checks or not based on the last couple of comments in that
bug.
Cheers,
Nathan
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/3] Revert "hardening: Disable GCC randstruct for COMPILE_TEST"
2025-05-30 19:09 ` Nathan Chancellor
@ 2025-05-30 19:37 ` Kees Cook
2025-05-30 22:31 ` Kees Cook
1 sibling, 0 replies; 17+ messages in thread
From: Kees Cook @ 2025-05-30 19:37 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Thiago Jung Bauermann, akpm, arnd, broonie, davidgow,
diego.daniel.professional, gnoack, gustavoars, jmorris,
justinstitt, linux-hardening, linux-kernel, linux-security-module,
linux, llvm, mcgrof, mic, morbo, nick.desaulniers+lkml, paul,
pmladek, rmoar, serge, tamird, wangyuli
On Fri, May 30, 2025 at 12:09:04PM -0700, Nathan Chancellor wrote:
> On Thu, May 29, 2025 at 10:12:22PM -0700, Kees Cook wrote:
> > On Thu, May 29, 2025 at 09:06:46PM -0300, Thiago Jung Bauermann wrote:
> > > This commit was reported by our CI as breaking the allmodconfig build for
> > > the arm and arm64 architectures when using GCC 15. This is due to
> > > https://github.com/KSPP/linux/issues/367 :
> > >
> > > 00:05:08 arch/arm64/kernel/kexec_image.c:132:14: internal compiler error: in comptypes_check_enum_int, at c/c-typeck.cc:1519
> > > 00:05:08 132 | const struct kexec_file_ops kexec_image_ops = {
> > > 00:05:08 | ^~~~~~~~~~~~~~
> >
> > I'm not able to reproduce this. Which specific version of GCC 15 and
> > on what distro are you seeing this?
>
> It looks like this was also reported to Debian (I originally noticed it
> in the #gcc channel on OFTC a couple of weeks ago but forgot to mention
> it):
>
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1104745
>
> It looks like the difference might be whether GCC was built with
> additional checks or not based on the last couple of comments in that
> bug.
Ah, thanks for the additional pointer! Yeah, discussion has continued
on https://github.com/KSPP/linux/issues/367 which shows it's a problem
for GCC builds configured with "--enable-checking=yes"
It seems like this check is overly strict? I'm building GCC now to see
which aspect of the plugin is tripping it... I assume its decl
finalization, but we'll see.
--
Kees Cook
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/3] Revert "hardening: Disable GCC randstruct for COMPILE_TEST"
2025-05-30 19:09 ` Nathan Chancellor
2025-05-30 19:37 ` Kees Cook
@ 2025-05-30 22:31 ` Kees Cook
1 sibling, 0 replies; 17+ messages in thread
From: Kees Cook @ 2025-05-30 22:31 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Thiago Jung Bauermann, akpm, arnd, broonie, davidgow,
diego.daniel.professional, gnoack, gustavoars, jmorris,
justinstitt, linux-hardening, linux-kernel, linux-security-module,
linux, llvm, mcgrof, mic, morbo, nick.desaulniers+lkml, paul,
pmladek, rmoar, serge, tamird, wangyuli
On Fri, May 30, 2025 at 12:09:04PM -0700, Nathan Chancellor wrote:
> On Thu, May 29, 2025 at 10:12:22PM -0700, Kees Cook wrote:
> > On Thu, May 29, 2025 at 09:06:46PM -0300, Thiago Jung Bauermann wrote:
> > > This commit was reported by our CI as breaking the allmodconfig build for
> > > the arm and arm64 architectures when using GCC 15. This is due to
> > > https://github.com/KSPP/linux/issues/367 :
> > >
> > > 00:05:08 arch/arm64/kernel/kexec_image.c:132:14: internal compiler error: in comptypes_check_enum_int, at c/c-typeck.cc:1519
> > > 00:05:08 132 | const struct kexec_file_ops kexec_image_ops = {
> > > 00:05:08 | ^~~~~~~~~~~~~~
> >
> > I'm not able to reproduce this. Which specific version of GCC 15 and
> > on what distro are you seeing this?
>
> It looks like this was also reported to Debian (I originally noticed it
> in the #gcc channel on OFTC a couple of weeks ago but forgot to mention
> it):
>
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1104745
>
> It looks like the difference might be whether GCC was built with
> additional checks or not based on the last couple of comments in that
> bug.
Proposed fix here:
https://lore.kernel.org/lkml/20250530221824.work.623-kees@kernel.org/
--
Kees Cook
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2025-05-30 22:31 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-27 1:38 [PATCH 0/3] randstruct: gcc-plugin: Remove bogus void member Kees Cook
2025-04-27 1:38 ` [PATCH 1/3] " Kees Cook
2025-04-27 1:38 ` [PATCH 2/3] lib/tests: Add randstruct KUnit test Kees Cook
2025-04-27 3:47 ` kernel test robot
2025-04-27 3:47 ` kernel test robot
2025-04-30 18:56 ` Kees Cook
2025-04-27 6:04 ` kernel test robot
2025-04-29 7:44 ` David Gow
2025-04-30 18:56 ` Kees Cook
2025-04-27 1:38 ` [PATCH 3/3] Revert "hardening: Disable GCC randstruct for COMPILE_TEST" Kees Cook
2025-05-30 0:06 ` Thiago Jung Bauermann
2025-05-30 5:12 ` Kees Cook
2025-05-30 19:09 ` Nathan Chancellor
2025-05-30 19:37 ` Kees Cook
2025-05-30 22:31 ` Kees Cook
2025-05-20 15:18 ` [PATCH 0/3] randstruct: gcc-plugin: Remove bogus void member Mickaël Salaün
2025-05-20 16:14 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).