public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Kees Cook <kees@kernel.org>, David Gow <davidgow@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] lib/tests: split randstruct initializer tests
Date: Fri, 20 Jun 2025 13:20:29 +0200	[thread overview]
Message-ID: <20250620112034.3395968-1-arnd@kernel.org> (raw)

From: Arnd Bergmann <arnd@arndb.de>

kunit code tents to cause problems with stack usage, especially when
sanitizers are enabled.

lib/tests/randstruct_kunit.c:306:1: error: the frame size of 1520 bytes is larger than 1280 bytes [-Werror=frame-larger-than=]

Splitting up the randstruct_initializers() function into two halves
helps since each side now stays below 1KB of stack even with sanitizers
enabled.

Fixes: b370f7eacdcf ("lib/tests: Add randstruct KUnit test")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 lib/tests/randstruct_kunit.c | 65 +++++++++++++++++++++++-------------
 1 file changed, 42 insertions(+), 23 deletions(-)

diff --git a/lib/tests/randstruct_kunit.c b/lib/tests/randstruct_kunit.c
index f3a2d63c4cfb..74211e2f186f 100644
--- a/lib/tests/randstruct_kunit.c
+++ b/lib/tests/randstruct_kunit.c
@@ -249,16 +249,6 @@ static void randstruct_initializers(struct kunit *test)
 	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 = {
@@ -274,6 +264,47 @@ static void randstruct_initializers(struct kunit *test)
 			init_members
 		});
 
+	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 void randstruct_contains_initializers(struct kunit *test)
+{
+#define init_members		\
+		.a = 1,		\
+		.b = 3,		\
+		.c = 5,		\
+		.d = 7,		\
+		.e = 11,	\
+		.f = 13,	\
+		.g = 17,	\
+		.h = 19,
+	struct contains_randstruct_untouched contains_untouched = {
+		.untouched = {
+			init_members
+		},
+	};
+	struct contains_randstruct_shuffled contains_shuffled = {
+		.shuffled = {
+			init_members
+		},
+	};
+	struct randstruct_shuffled 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){
@@ -289,19 +320,6 @@ static void randstruct_initializers(struct kunit *test)
 			.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
 }
 
@@ -319,6 +337,7 @@ static struct kunit_case randstruct_test_cases[] = {
 	KUNIT_CASE(randstruct_layout_fptr),
 	KUNIT_CASE(randstruct_layout_fptr_deep),
 	KUNIT_CASE(randstruct_initializers),
+	KUNIT_CASE(randstruct_contains_initializers),
 	{}
 };
 
-- 
2.39.5


                 reply	other threads:[~2025-06-20 11:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250620112034.3395968-1-arnd@kernel.org \
    --to=arnd@kernel.org \
    --cc=arnd@arndb.de \
    --cc=davidgow@google.com \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox