1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Test cases for compiler-based stack variable zeroing via
4  * -ftrivial-auto-var-init={zero,pattern} or CONFIG_GCC_PLUGIN_STRUCTLEAK*.
5  * For example, see:
6  * "Running tests with kunit_tool" at Documentation/dev-tools/kunit/start.rst
7  *	./tools/testing/kunit/kunit.py run stackinit [--raw_output] \
8  *		--make_option LLVM=1 \
9  *		--kconfig_add CONFIG_INIT_STACK_ALL_ZERO=y
10  *
11  */
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 
14 #include <kunit/test.h>
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/string.h>
19 
20 /* Exfiltration buffer. */
21 #define MAX_VAR_SIZE	128
22 static u8 check_buf[MAX_VAR_SIZE];
23 
24 /* Character array to trigger stack protector in all functions. */
25 #define VAR_BUFFER	 32
26 
27 /* Volatile mask to convince compiler to copy memory with 0xff. */
28 static volatile u8 forced_mask = 0xff;
29 
30 /* Location and size tracking to validate fill and test are colocated. */
31 static void *fill_start, *target_start;
32 static size_t fill_size, target_size;
33 
stackinit_range_contains(char * haystack_start,size_t haystack_size,char * needle_start,size_t needle_size)34 static bool stackinit_range_contains(char *haystack_start, size_t haystack_size,
35 				     char *needle_start, size_t needle_size)
36 {
37 	if (needle_start >= haystack_start &&
38 	    needle_start + needle_size <= haystack_start + haystack_size)
39 		return true;
40 	return false;
41 }
42 
43 /* Whether the test is expected to fail. */
44 #define WANT_SUCCESS				0
45 #define XFAIL					1
46 
47 #define DO_NOTHING_TYPE_SCALAR(var_type)	var_type
48 #define DO_NOTHING_TYPE_STRING(var_type)	void
49 #define DO_NOTHING_TYPE_STRUCT(var_type)	void
50 #define DO_NOTHING_TYPE_UNION(var_type)		void
51 
52 #define DO_NOTHING_RETURN_SCALAR(ptr)		*(ptr)
53 #define DO_NOTHING_RETURN_STRING(ptr)		/**/
54 #define DO_NOTHING_RETURN_STRUCT(ptr)		/**/
55 #define DO_NOTHING_RETURN_UNION(ptr)		/**/
56 
57 #define DO_NOTHING_CALL_SCALAR(var, name)			\
58 		(var) = do_nothing_ ## name(&(var))
59 #define DO_NOTHING_CALL_STRING(var, name)			\
60 		do_nothing_ ## name(var)
61 #define DO_NOTHING_CALL_STRUCT(var, name)			\
62 		do_nothing_ ## name(&(var))
63 #define DO_NOTHING_CALL_UNION(var, name)			\
64 		do_nothing_ ## name(&(var))
65 
66 #define FETCH_ARG_SCALAR(var)		&var
67 #define FETCH_ARG_STRING(var)		var
68 #define FETCH_ARG_STRUCT(var)		&var
69 #define FETCH_ARG_UNION(var)		&var
70 
71 /*
72  * On m68k, if the leaf function test variable is longer than 8 bytes,
73  * the start of the stack frame moves. 8 is sufficiently large to
74  * test m68k char arrays, but leave it at 16 for other architectures.
75  */
76 #ifdef CONFIG_M68K
77 #define FILL_SIZE_STRING		8
78 #define FILL_SIZE_ARRAY			2
79 #else
80 #define FILL_SIZE_STRING		16
81 #define FILL_SIZE_ARRAY			8
82 #endif
83 
84 #define INIT_CLONE_SCALAR		/**/
85 #define INIT_CLONE_STRING		[FILL_SIZE_STRING]
86 #define INIT_CLONE_STRUCT		/**/
87 #define INIT_CLONE_UNION		/**/
88 
89 #define ZERO_CLONE_SCALAR(zero)		memset(&(zero), 0x00, sizeof(zero))
90 #define ZERO_CLONE_STRING(zero)		memset(&(zero), 0x00, sizeof(zero))
91 /*
92  * For the struct, intentionally poison padding to see if it gets
93  * copied out in direct assignments.
94  * */
95 #define ZERO_CLONE_STRUCT(zero)				\
96 	do {						\
97 		memset(&(zero), 0xFF, sizeof(zero));	\
98 		zero.one = 0;				\
99 		zero.two = 0;				\
100 		zero.three = 0;				\
101 		zero.four = 0;				\
102 	} while (0)
103 #define ZERO_CLONE_UNION(zero)		ZERO_CLONE_STRUCT(zero)
104 
105 #define INIT_SCALAR_none(var_type)	/**/
106 #define INIT_SCALAR_zero(var_type)	= 0
107 
108 #define INIT_STRING_none(var_type)	[FILL_SIZE_STRING] /**/
109 #define INIT_STRING_zero(var_type)	[FILL_SIZE_STRING] = { }
110 
111 #define INIT_STRUCT_none(var_type)	/**/
112 #define INIT_STRUCT_zero(var_type)	= { }
113 #define INIT_STRUCT_old_zero(var_type)	= { 0 }
114 
115 
116 #define __static_partial		{ .two = 0, }
117 #define __static_all			{ .one = 0,			\
118 					  .two = 0,			\
119 					  .three = 0,			\
120 					  .four = 0,			\
121 					}
122 #define __dynamic_partial		{ .two = arg->two, }
123 #define __dynamic_all			{ .one = arg->one,		\
124 					  .two = arg->two,		\
125 					  .three = arg->three,		\
126 					  .four = arg->four,		\
127 					}
128 #define __runtime_partial		var.two = 0
129 #define __runtime_all			var.one = 0;			\
130 					var.two = 0;			\
131 					var.three = 0;			\
132 					var.four = 0
133 
134 #define INIT_STRUCT_static_partial(var_type)				\
135 					= __static_partial
136 #define INIT_STRUCT_static_all(var_type)				\
137 					= __static_all
138 #define INIT_STRUCT_dynamic_partial(var_type)				\
139 					= __dynamic_partial
140 #define INIT_STRUCT_dynamic_all(var_type)				\
141 					= __dynamic_all
142 #define INIT_STRUCT_runtime_partial(var_type)				\
143 					; __runtime_partial
144 #define INIT_STRUCT_runtime_all(var_type)				\
145 					; __runtime_all
146 
147 #define INIT_STRUCT_assigned_static_partial(var_type)			\
148 					; var = (var_type)__static_partial
149 #define INIT_STRUCT_assigned_static_all(var_type)			\
150 					; var = (var_type)__static_all
151 #define INIT_STRUCT_assigned_dynamic_partial(var_type)			\
152 					; var = (var_type)__dynamic_partial
153 #define INIT_STRUCT_assigned_dynamic_all(var_type)			\
154 					; var = (var_type)__dynamic_all
155 
156 #define INIT_STRUCT_assigned_copy(var_type)				\
157 					; var = *(arg)
158 
159 /* Union initialization is the same as structs. */
160 #define INIT_UNION_none(var_type)	INIT_STRUCT_none(var_type)
161 #define INIT_UNION_zero(var_type)	INIT_STRUCT_zero(var_type)
162 #define INIT_UNION_old_zero(var_type)	INIT_STRUCT_old_zero(var_type)
163 
164 #define INIT_UNION_static_partial(var_type)		\
165 	INIT_STRUCT_static_partial(var_type)
166 #define INIT_UNION_static_all(var_type)			\
167 	INIT_STRUCT_static_all(var_type)
168 #define INIT_UNION_dynamic_partial(var_type)		\
169 	INIT_STRUCT_dynamic_partial(var_type)
170 #define INIT_UNION_dynamic_all(var_type)		\
171 	INIT_STRUCT_dynamic_all(var_type)
172 #define INIT_UNION_runtime_partial(var_type)		\
173 	INIT_STRUCT_runtime_partial(var_type)
174 #define INIT_UNION_runtime_all(var_type)		\
175 	INIT_STRUCT_runtime_all(var_type)
176 #define INIT_UNION_assigned_static_partial(var_type)	\
177 	INIT_STRUCT_assigned_static_partial(var_type)
178 #define INIT_UNION_assigned_static_all(var_type)	\
179 	INIT_STRUCT_assigned_static_all(var_type)
180 #define INIT_UNION_assigned_dynamic_partial(var_type)	\
181 	INIT_STRUCT_assigned_dynamic_partial(var_type)
182 #define INIT_UNION_assigned_dynamic_all(var_type)	\
183 	INIT_STRUCT_assigned_dynamic_all(var_type)
184 #define INIT_UNION_assigned_copy(var_type)		\
185 	INIT_STRUCT_assigned_copy(var_type)
186 
187 /*
188  * The "did we actually fill the stack?" check value needs
189  * to be neither 0 nor any of the "pattern" bytes. The
190  * pattern bytes are compiler, architecture, and type based,
191  * so we have to pick a value that never appears for those
192  * combinations. Use 0x99 which is not 0xFF, 0xFE, nor 0xAA.
193  */
194 #define FILL_BYTE	0x99
195 
196 /*
197  * @name: unique string name for the test
198  * @var_type: type to be tested for zeroing initialization
199  * @which: is this a SCALAR, STRING, or STRUCT type?
200  * @init_level: what kind of initialization is performed
201  * @xfail: is this test expected to fail?
202  */
203 #define DEFINE_TEST_DRIVER(name, var_type, which, xfail)	\
204 /* Returns 0 on success, 1 on failure. */			\
205 static noinline void test_ ## name (struct kunit *test)		\
206 {								\
207 	var_type zero INIT_CLONE_ ## which;			\
208 	int ignored;						\
209 	u8 sum = 0, i;						\
210 								\
211 	/* Notice when a new test is larger than expected. */	\
212 	BUILD_BUG_ON(sizeof(zero) > MAX_VAR_SIZE);		\
213 								\
214 	/* Fill clone type with zero for per-field init. */	\
215 	ZERO_CLONE_ ## which(zero);				\
216 	/* Clear entire check buffer for 0xFF overlap test. */	\
217 	memset(check_buf, 0x00, sizeof(check_buf));		\
218 	/* Fill stack with FILL_BYTE. */			\
219 	ignored = leaf_ ##name((unsigned long)&ignored, 1,	\
220 				FETCH_ARG_ ## which(zero));	\
221 	/* Verify all bytes overwritten with FILL_BYTE. */	\
222 	for (sum = 0, i = 0; i < target_size; i++)		\
223 		sum += (check_buf[i] != FILL_BYTE);		\
224 	/* Clear entire check buffer for later bit tests. */	\
225 	memset(check_buf, 0x00, sizeof(check_buf));		\
226 	/* Extract stack-defined variable contents. */		\
227 	ignored = leaf_ ##name((unsigned long)&ignored, 0,	\
228 				FETCH_ARG_ ## which(zero));	\
229 	/*							\
230 	 * Delay the sum test to here to do as little as	\
231 	 * possible between the two leaf function calls.	\
232 	 */							\
233 	KUNIT_ASSERT_EQ_MSG(test, sum, 0,			\
234 			    "leaf fill was not 0x%02X!?\n",	\
235 			    FILL_BYTE);				\
236 								\
237 	/* Validate that compiler lined up fill and target. */	\
238 	KUNIT_ASSERT_TRUE_MSG(test,				\
239 		stackinit_range_contains(fill_start, fill_size,	\
240 			    target_start, target_size),		\
241 		"stackframe was not the same between calls!? "	\
242 		"(fill %zu wide, target offset by %d)\n",	\
243 		fill_size,					\
244 		(int)((ssize_t)(uintptr_t)fill_start -		\
245 		      (ssize_t)(uintptr_t)target_start));	\
246 								\
247 	/* Validate check region has no FILL_BYTE bytes. */	\
248 	for (sum = 0, i = 0; i < target_size; i++)		\
249 		sum += (check_buf[i] == FILL_BYTE);		\
250 								\
251 	if (sum != 0 && xfail)					\
252 		kunit_skip(test,				\
253 			   "XFAIL uninit bytes: %d\n",		\
254 			   sum);				\
255 	KUNIT_ASSERT_EQ_MSG(test, sum, 0,			\
256 		"uninit bytes: %d\n", sum);			\
257 }
258 #define DEFINE_TEST(name, var_type, which, init_level, xfail)	\
259 /* no-op to force compiler into ignoring "uninitialized" vars */\
260 static noinline DO_NOTHING_TYPE_ ## which(var_type)		\
261 do_nothing_ ## name(var_type *ptr)				\
262 {								\
263 	OPTIMIZER_HIDE_VAR(ptr);				\
264 	/* Will always be true, but compiler doesn't know. */	\
265 	if ((unsigned long)ptr > 0x2)				\
266 		return DO_NOTHING_RETURN_ ## which(ptr);	\
267 	else							\
268 		return DO_NOTHING_RETURN_ ## which(ptr + 1);	\
269 }								\
270 static noinline int leaf_ ## name(unsigned long sp, bool fill,	\
271 				  var_type *arg)		\
272 {								\
273 	char buf[VAR_BUFFER];					\
274 	var_type var						\
275 		INIT_ ## which ## _ ## init_level(var_type);	\
276 								\
277 	target_start = &var;					\
278 	target_size = sizeof(var);				\
279 	/*							\
280 	 * Keep this buffer around to make sure we've got a	\
281 	 * stack frame of SOME kind...				\
282 	 */							\
283 	memset(buf, (char)(sp & 0xff), sizeof(buf));		\
284 	/* Fill variable with FILL_BYTE. */			\
285 	if (fill) {						\
286 		fill_start = &var;				\
287 		fill_size = sizeof(var);			\
288 		memset(fill_start,				\
289 		       FILL_BYTE & forced_mask,			\
290 		       fill_size);				\
291 	}							\
292 								\
293 	/* Silence "never initialized" warnings. */		\
294 	DO_NOTHING_CALL_ ## which(var, name);			\
295 								\
296 	/* Exfiltrate "var". */					\
297 	memcpy(check_buf, target_start, target_size);		\
298 								\
299 	return (int)buf[0] | (int)buf[sizeof(buf) - 1];		\
300 }								\
301 DEFINE_TEST_DRIVER(name, var_type, which, xfail)
302 
303 /* Structure with no padding. */
304 struct test_packed {
305 	unsigned long one;
306 	unsigned long two;
307 	unsigned long three;
308 	unsigned long four;
309 };
310 
311 /* Simple structure with padding likely to be covered by compiler. */
312 struct test_small_hole {
313 	size_t one;
314 	char two;
315 	/* 3 byte padding hole here. */
316 	int three;
317 	unsigned long four;
318 };
319 
320 /* Trigger unhandled padding in a structure. */
321 struct test_big_hole {
322 	u8 one;
323 	u8 two;
324 	u8 three;
325 	/* 61 byte padding hole here. */
326 	u8 four __aligned(64);
327 } __aligned(64);
328 
329 struct test_trailing_hole {
330 	char *one;
331 	char *two;
332 	char *three;
333 	char four;
334 	/* "sizeof(unsigned long) - 1" byte padding hole here. */
335 };
336 
337 /* Test if STRUCTLEAK is clearing structs with __user fields. */
338 struct test_user {
339 	u8 one;
340 	unsigned long two;
341 	char __user *three;
342 	unsigned long four;
343 };
344 
345 /* No padding: all members are the same size. */
346 union test_same_sizes {
347 	unsigned long one;
348 	unsigned long two;
349 	unsigned long three;
350 	unsigned long four;
351 };
352 
353 /* Mismatched sizes, with one and two being small */
354 union test_small_start {
355 	char one:1;
356 	char two;
357 	short three;
358 	unsigned long four;
359 	struct big_struct {
360 		unsigned long array[FILL_SIZE_ARRAY];
361 	} big;
362 };
363 
364 /* Mismatched sizes, with three and four being small */
365 union test_small_end {
366 	short one;
367 	unsigned long two;
368 	char three:1;
369 	char four;
370 };
371 
372 #define ALWAYS_PASS	WANT_SUCCESS
373 #define ALWAYS_FAIL	XFAIL
374 
375 #ifdef CONFIG_INIT_STACK_NONE
376 # define USER_PASS	XFAIL
377 # define BYREF_PASS	XFAIL
378 # define STRONG_PASS	XFAIL
379 #elif defined(CONFIG_GCC_PLUGIN_STRUCTLEAK_USER)
380 # define USER_PASS	WANT_SUCCESS
381 # define BYREF_PASS	XFAIL
382 # define STRONG_PASS	XFAIL
383 #elif defined(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF)
384 # define USER_PASS	WANT_SUCCESS
385 # define BYREF_PASS	WANT_SUCCESS
386 # define STRONG_PASS	XFAIL
387 #else
388 # define USER_PASS	WANT_SUCCESS
389 # define BYREF_PASS	WANT_SUCCESS
390 # define STRONG_PASS	WANT_SUCCESS
391 #endif
392 
393 #define DEFINE_SCALAR_TEST(name, init, xfail)			\
394 		DEFINE_TEST(name ## _ ## init, name, SCALAR,	\
395 			    init, xfail)
396 
397 #define DEFINE_SCALAR_TESTS(init, xfail)			\
398 		DEFINE_SCALAR_TEST(u8, init, xfail);		\
399 		DEFINE_SCALAR_TEST(u16, init, xfail);		\
400 		DEFINE_SCALAR_TEST(u32, init, xfail);		\
401 		DEFINE_SCALAR_TEST(u64, init, xfail);		\
402 		DEFINE_TEST(char_array_ ## init, unsigned char,	\
403 			    STRING, init, xfail)
404 
405 #define DEFINE_STRUCT_TEST(name, init, xfail)			\
406 		DEFINE_TEST(name ## _ ## init,			\
407 			    struct test_ ## name, STRUCT, init, \
408 			    xfail)
409 
410 #define DEFINE_UNION_TEST(name, init, xfail)			\
411 		DEFINE_TEST(name ## _ ## init,			\
412 			    union test_ ## name, STRUCT, init,	\
413 			    xfail)
414 
415 #define DEFINE_STRUCT_TESTS(init, xfail)			\
416 		DEFINE_STRUCT_TEST(small_hole, init, xfail);	\
417 		DEFINE_STRUCT_TEST(big_hole, init, xfail);	\
418 		DEFINE_STRUCT_TEST(trailing_hole, init, xfail);	\
419 		DEFINE_STRUCT_TEST(packed, init, xfail)
420 
421 #define DEFINE_STRUCT_INITIALIZER_TESTS(base, xfail)		\
422 		DEFINE_STRUCT_TESTS(base ## _ ## partial,	\
423 				    xfail);			\
424 		DEFINE_STRUCT_TESTS(base ## _ ## all, xfail)
425 
426 #define DEFINE_UNION_INITIALIZER_TESTS(base, xfail)		\
427 		DEFINE_UNION_TESTS(base ## _ ## partial,	\
428 				    xfail);			\
429 		DEFINE_UNION_TESTS(base ## _ ## all, xfail)
430 
431 #define DEFINE_UNION_TESTS(init, xfail)				\
432 		DEFINE_UNION_TEST(same_sizes, init, xfail);	\
433 		DEFINE_UNION_TEST(small_start, init, xfail);	\
434 		DEFINE_UNION_TEST(small_end, init, xfail);
435 
436 /* These should be fully initialized all the time! */
437 DEFINE_SCALAR_TESTS(zero, ALWAYS_PASS);
438 DEFINE_STRUCT_TESTS(zero, ALWAYS_PASS);
439 DEFINE_STRUCT_TESTS(old_zero, ALWAYS_PASS);
440 DEFINE_UNION_TESTS(zero, ALWAYS_PASS);
441 DEFINE_UNION_TESTS(old_zero, ALWAYS_PASS);
442 /* Struct initializers: padding may be left uninitialized. */
443 DEFINE_STRUCT_INITIALIZER_TESTS(static, STRONG_PASS);
444 DEFINE_STRUCT_INITIALIZER_TESTS(dynamic, STRONG_PASS);
445 DEFINE_STRUCT_INITIALIZER_TESTS(runtime, STRONG_PASS);
446 DEFINE_STRUCT_INITIALIZER_TESTS(assigned_static, STRONG_PASS);
447 DEFINE_STRUCT_INITIALIZER_TESTS(assigned_dynamic, STRONG_PASS);
448 DEFINE_STRUCT_TESTS(assigned_copy, ALWAYS_FAIL);
449 DEFINE_UNION_INITIALIZER_TESTS(static, STRONG_PASS);
450 DEFINE_UNION_INITIALIZER_TESTS(dynamic, STRONG_PASS);
451 DEFINE_UNION_INITIALIZER_TESTS(runtime, STRONG_PASS);
452 DEFINE_UNION_INITIALIZER_TESTS(assigned_static, STRONG_PASS);
453 DEFINE_UNION_INITIALIZER_TESTS(assigned_dynamic, STRONG_PASS);
454 DEFINE_UNION_TESTS(assigned_copy, ALWAYS_FAIL);
455 /* No initialization without compiler instrumentation. */
456 DEFINE_SCALAR_TESTS(none, STRONG_PASS);
457 DEFINE_STRUCT_TESTS(none, BYREF_PASS);
458 /* Initialization of members with __user attribute. */
459 DEFINE_TEST(user, struct test_user, STRUCT, none, USER_PASS);
460 
461 /*
462  * Check two uses through a variable declaration outside either path,
463  * which was noticed as a special case in porting earlier stack init
464  * compiler logic.
465  */
__leaf_switch_none(int path,bool fill)466 static int noinline __leaf_switch_none(int path, bool fill)
467 {
468 	switch (path) {
469 		/*
470 		 * This is intentionally unreachable. To silence the
471 		 * warning, build with -Wno-switch-unreachable
472 		 */
473 		uint64_t var[10];
474 
475 	case 1:
476 		target_start = &var;
477 		target_size = sizeof(var);
478 		if (fill) {
479 			fill_start = &var;
480 			fill_size = sizeof(var);
481 
482 			memset(fill_start, (forced_mask | 0x55) & FILL_BYTE, fill_size);
483 		}
484 		memcpy(check_buf, target_start, target_size);
485 		break;
486 	case 2:
487 		target_start = &var;
488 		target_size = sizeof(var);
489 		if (fill) {
490 			fill_start = &var;
491 			fill_size = sizeof(var);
492 
493 			memset(fill_start, (forced_mask | 0xaa) & FILL_BYTE, fill_size);
494 		}
495 		memcpy(check_buf, target_start, target_size);
496 		break;
497 	default:
498 		var[1] = 5;
499 		return var[1] & forced_mask;
500 	}
501 	return 0;
502 }
503 
leaf_switch_1_none(unsigned long sp,bool fill,uint64_t * arg)504 static noinline int leaf_switch_1_none(unsigned long sp, bool fill,
505 					      uint64_t *arg)
506 {
507 	return __leaf_switch_none(1, fill);
508 }
509 
leaf_switch_2_none(unsigned long sp,bool fill,uint64_t * arg)510 static noinline int leaf_switch_2_none(unsigned long sp, bool fill,
511 					      uint64_t *arg)
512 {
513 	return __leaf_switch_none(2, fill);
514 }
515 
516 /*
517  * These are expected to fail for most configurations because neither
518  * GCC nor Clang have a way to perform initialization of variables in
519  * non-code areas (i.e. in a switch statement before the first "case").
520  * https://llvm.org/pr44916
521  */
522 DEFINE_TEST_DRIVER(switch_1_none, uint64_t, SCALAR, ALWAYS_FAIL);
523 DEFINE_TEST_DRIVER(switch_2_none, uint64_t, SCALAR, ALWAYS_FAIL);
524 
525 #define KUNIT_test_scalars(init)			\
526 		KUNIT_CASE(test_u8_ ## init),		\
527 		KUNIT_CASE(test_u16_ ## init),		\
528 		KUNIT_CASE(test_u32_ ## init),		\
529 		KUNIT_CASE(test_u64_ ## init),		\
530 		KUNIT_CASE(test_char_array_ ## init)
531 
532 #define KUNIT_test_structs(init)			\
533 		KUNIT_CASE(test_small_hole_ ## init),	\
534 		KUNIT_CASE(test_big_hole_ ## init),	\
535 		KUNIT_CASE(test_trailing_hole_ ## init),\
536 		KUNIT_CASE(test_packed_ ## init)	\
537 
538 #define KUNIT_test_unions(init)				\
539 		KUNIT_CASE(test_same_sizes_ ## init),	\
540 		KUNIT_CASE(test_small_start_ ## init),	\
541 		KUNIT_CASE(test_small_end_ ## init)	\
542 
543 static struct kunit_case stackinit_test_cases[] = {
544 	/* These are explicitly initialized and should always pass. */
545 	KUNIT_test_scalars(zero),
546 	KUNIT_test_structs(zero),
547 	KUNIT_test_structs(old_zero),
548 	KUNIT_test_unions(zero),
549 	KUNIT_test_unions(old_zero),
550 	/* Padding here appears to be accidentally always initialized? */
551 	KUNIT_test_structs(dynamic_partial),
552 	KUNIT_test_structs(assigned_dynamic_partial),
553 	KUNIT_test_unions(dynamic_partial),
554 	KUNIT_test_unions(assigned_dynamic_partial),
555 	/* Padding initialization depends on compiler behaviors. */
556 	KUNIT_test_structs(static_partial),
557 	KUNIT_test_structs(static_all),
558 	KUNIT_test_structs(dynamic_all),
559 	KUNIT_test_structs(runtime_partial),
560 	KUNIT_test_structs(runtime_all),
561 	KUNIT_test_structs(assigned_static_partial),
562 	KUNIT_test_structs(assigned_static_all),
563 	KUNIT_test_structs(assigned_dynamic_all),
564 	KUNIT_test_unions(static_partial),
565 	KUNIT_test_unions(static_all),
566 	KUNIT_test_unions(dynamic_all),
567 	KUNIT_test_unions(runtime_partial),
568 	KUNIT_test_unions(runtime_all),
569 	KUNIT_test_unions(assigned_static_partial),
570 	KUNIT_test_unions(assigned_static_all),
571 	KUNIT_test_unions(assigned_dynamic_all),
572 	/* Everything fails this since it effectively performs a memcpy(). */
573 	KUNIT_test_structs(assigned_copy),
574 	KUNIT_test_unions(assigned_copy),
575 	/* STRUCTLEAK_BYREF_ALL should cover everything from here down. */
576 	KUNIT_test_scalars(none),
577 	KUNIT_CASE(test_switch_1_none),
578 	KUNIT_CASE(test_switch_2_none),
579 	/* STRUCTLEAK_BYREF should cover from here down. */
580 	KUNIT_test_structs(none),
581 	/* STRUCTLEAK will only cover this. */
582 	KUNIT_CASE(test_user),
583 	{}
584 };
585 
586 static struct kunit_suite stackinit_test_suite = {
587 	.name = "stackinit",
588 	.test_cases = stackinit_test_cases,
589 };
590 
591 kunit_test_suites(&stackinit_test_suite);
592 
593 MODULE_DESCRIPTION("Test cases for compiler-based stack variable zeroing");
594 MODULE_LICENSE("GPL");
595