Skip to content

Commit c2efa53

Browse files
committed
lib: stackinit: Adjust target string to 8 bytes for m68k
For reasons I cannot understand, m68k moves the start of the stack frame for consecutive calls to the same function if the function's test variable is larger than 8 bytes. This was only happening for the char array test (obviously), so adjust the length of the string for m68k only. I want the array size to be longer than "unsigned long" for every given architecture, so the other remain unchanged. Additionally adjust the error message to be a bit more clear about what's happened, and move the KUNIT check outside of the consecutive calls to minimize what happens between them. Reported-by: Guenter Roeck <[email protected]> Closes: https://lore.kernel.org/lkml/[email protected]/ Tested-by: Guenter Roeck <[email protected]> Reported-by: Geert Uytterhoeven <[email protected]> Closes: https://lore.kernel.org/r/CAMuHMdX_g1tbiUL9PUQdqaegrEzCNN3GtbSvSBFYAL4TzvstFg@mail.gmail.com Closes: https://lore.kernel.org/r/CAMuHMdW6N40+0gGQ+LSrN64Mo4A0-ELAm0pR3gWQ0mNanyBuUQ@mail.gmail.com Tested-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent d4be85d commit c2efa53

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/stackinit_kunit.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,16 @@ static bool stackinit_range_contains(char *haystack_start, size_t haystack_size,
6363
#define FETCH_ARG_STRING(var) var
6464
#define FETCH_ARG_STRUCT(var) &var
6565

66+
/*
67+
* On m68k, if the leaf function test variable is longer than 8 bytes,
68+
* the start of the stack frame moves. 8 is sufficiently large to
69+
* test m68k char arrays, but leave it at 16 for other architectures.
70+
*/
71+
#ifdef CONFIG_M68K
72+
#define FILL_SIZE_STRING 8
73+
#else
6674
#define FILL_SIZE_STRING 16
75+
#endif
6776

6877
#define INIT_CLONE_SCALAR /**/
6978
#define INIT_CLONE_STRING [FILL_SIZE_STRING]
@@ -165,19 +174,23 @@ static noinline void test_ ## name (struct kunit *test) \
165174
/* Verify all bytes overwritten with 0xFF. */ \
166175
for (sum = 0, i = 0; i < target_size; i++) \
167176
sum += (check_buf[i] != 0xFF); \
168-
KUNIT_ASSERT_EQ_MSG(test, sum, 0, \
169-
"leaf fill was not 0xFF!?\n"); \
170177
/* Clear entire check buffer for later bit tests. */ \
171178
memset(check_buf, 0x00, sizeof(check_buf)); \
172179
/* Extract stack-defined variable contents. */ \
173180
ignored = leaf_ ##name((unsigned long)&ignored, 0, \
174181
FETCH_ARG_ ## which(zero)); \
182+
/* \
183+
* Delay the sum test to here to do as little as \
184+
* possible between the two leaf function calls. \
185+
*/ \
186+
KUNIT_ASSERT_EQ_MSG(test, sum, 0, \
187+
"leaf fill was not 0xFF!?\n"); \
175188
\
176189
/* Validate that compiler lined up fill and target. */ \
177190
KUNIT_ASSERT_TRUE_MSG(test, \
178191
stackinit_range_contains(fill_start, fill_size, \
179192
target_start, target_size), \
180-
"stack fill missed target!? " \
193+
"stackframe was not the same between calls!? " \
181194
"(fill %zu wide, target offset by %d)\n", \
182195
fill_size, \
183196
(int)((ssize_t)(uintptr_t)fill_start - \

0 commit comments

Comments
 (0)