tools/nolibc: tests: use volatile to force stack smashing
authorThomas Weißschuh <linux@weissschuh.net>
Tue, 28 Mar 2023 16:18:45 +0000 (18:18 +0200)
committerPaul E. McKenney <paulmck@kernel.org>
Fri, 9 Jun 2023 18:33:04 +0000 (11:33 -0700)
Use a volatile pointer to write outside the buffer so the compiler can't
optimize it away.

Reported-by: Alexey Dobriyan <adobriyan@gmail.com>
Link: https://lore.kernel.org/lkml/c0584807-511c-4496-b062-1263ea38f349@p183/
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
tools/testing/selftests/nolibc/nolibc-test.c

index 21bacc928bf7b260518496fcecd0cf2960628a27..47013b78972e532f76a600913ddf0b85e0538f10 100644 (file)
@@ -667,17 +667,13 @@ int run_stdlib(int min, int max)
        return ret;
 }
 
-#if defined(__clang__)
-__attribute__((optnone))
-#elif defined(__GNUC__)
-__attribute__((optimize("O0")))
-#endif
 static int smash_stack(void)
 {
        char buf[100];
+       volatile char *ptr = buf;
 
        for (size_t i = 0; i < 200; i++)
-               buf[i] = 'P';
+               ptr[i] = 'P';
 
        return 1;
 }