lib: stackinit: Adjust target string to 8 bytes for m68k
PATCH 1/1 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.
---
Cc: Geert Uytterhoeven <[email protected]>
--- lib/stackinit_kunit.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
lib/stackinit_kunit.c +16 -3
@@ -63,7 +63,16 @@ static bool stackinit_range_contains(char *haystack_start, size_t haystack_size,#define FETCH_ARG_STRING (var) var#define FETCH_ARG_STRUCT (var) &var +/* +* On m68k, if the leaf function test variable is longer than 8 bytes, +* the start of the stack frame moves. 8 is sufficiently large to +* test m68k char arrays, but leave it at 16 for other architectures. +*/ +#ifdef CONFIG_M68K +#define FILL_SIZE_STRING 8 +#else #define FILL_SIZE_STRING 16 +#endif #define INIT_CLONE_SCALAR /**/ #define INIT_CLONE_STRING [FILL_SIZE_STRING]
@@ -165,19 +174,23 @@ static noinline void test_ ## name (struct kunit *test) \/* Verify all bytes overwritten with 0xFF. */ \for (sum =0 , i =0 ; i < target_size; i++) \ sum += (check_buf[i] !=0xFF ); \ -KUNIT_ASSERT_EQ_MSG (test, sum,0 , \ -"leaf fill was not 0xFF!?\n" ); \/* Clear entire check buffer for later bit tests. */ \memset (check_buf,0x00 ,sizeof (check_buf)); \/* Extract stack-defined variable contents. */ \ ignored = leaf_ ##name((unsigned long)&ignored, 0, \ FETCH_ARG_ ## which(zero)); \ +/* \ +* Delay the sum test to here to do as little as \ +* possible between the two leaf function calls. \ +*/ \ +KUNIT_ASSERT_EQ_MSG (test, sum,0 , \ +"leaf fill was not 0xFF!?\n" ); \ \/* Validate that compiler lined up fill and target. */ \ KUNIT_ASSERT_TRUE_MSG(test, \ stackinit_range_contains(fill_start, fill_size, \ target_start, target_size), \ - "stack fill missed target!? " \ + "stackframe was not the same between calls!? " \ "(fill %zu wide, target offset by %d)\n", \ fill_size, \ (int)((ssize_t)(uintptr_t)fill_start - \
Signature · 1 line
2.34.1
Quoted 2 lines · Kees Cook
For reasons I cannot understand, m68k moves the start of the stack frame for consecutive calls to the same function
It's called optimisation.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Quoted 7 lines · Kees Cook
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.
Quoted 7 lines
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]>Signed-off-by Kees Cook <[email protected]>
Hmm, guess I misunderstood the other e-mail.
Anyway, it works. After re-enabling the m68k tests:
I'll also run it through qemu for other architectures to be sure that there is no negative impact.
Thanks,
Guenter
Hi Kees,
Quoted 10 lines · Kees Cook
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.
Thanks for your patch!
Quoted 2 lines
Do reports have an expiration date? ;-)
Quoted 1 line
Signed-off-by Kees Cook <[email protected]>
Finally all parts of this test are passing on m68k, great!
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds