Skip to content

Commit f9398f1

Browse files
committed
lib/test_stackinit: Fix static initializer test
The static initializer test got accidentally converted to a dynamic initializer. Fix this and retain the giant padding hole without using an aligned struct member. Fixes: 50ceaa9 ("lib: Introduce test_stackinit module") Cc: Ard Biesheuvel <ardb@kernel.org> Cc: stable@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20210723221933.3431999-2-keescook@chromium.org
1 parent dcb7c0b commit f9398f1

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

lib/test_stackinit.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ static bool range_contains(char *haystack_start, size_t haystack_size,
6767
#define INIT_STRUCT_none /**/
6868
#define INIT_STRUCT_zero = { }
6969
#define INIT_STRUCT_static_partial = { .two = 0, }
70-
#define INIT_STRUCT_static_all = { .one = arg->one, \
71-
.two = arg->two, \
72-
.three = arg->three, \
73-
.four = arg->four, \
70+
#define INIT_STRUCT_static_all = { .one = 0, \
71+
.two = 0, \
72+
.three = 0, \
73+
.four = 0, \
7474
}
7575
#define INIT_STRUCT_dynamic_partial = { .two = arg->two, }
7676
#define INIT_STRUCT_dynamic_all = { .one = arg->one, \
@@ -84,8 +84,7 @@ static bool range_contains(char *haystack_start, size_t haystack_size,
8484
var.one = 0; \
8585
var.two = 0; \
8686
var.three = 0; \
87-
memset(&var.four, 0, \
88-
sizeof(var.four))
87+
var.four = 0
8988

9089
/*
9190
* @name: unique string name for the test
@@ -210,18 +209,13 @@ struct test_small_hole {
210209
unsigned long four;
211210
};
212211

213-
/* Try to trigger unhandled padding in a structure. */
214-
struct test_aligned {
215-
u32 internal1;
216-
u64 internal2;
217-
} __aligned(64);
218-
212+
/* Trigger unhandled padding in a structure. */
219213
struct test_big_hole {
220214
u8 one;
221215
u8 two;
222216
u8 three;
223217
/* 61 byte padding hole here. */
224-
struct test_aligned four;
218+
u8 four __aligned(64);
225219
} __aligned(64);
226220

227221
struct test_trailing_hole {

0 commit comments

Comments
 (0)