Skip to content
Snippets Groups Projects
Commit 59d451e3 authored by Philipp Spilger's avatar Philipp Spilger Committed by Yannik Stradmann
Browse files

Fix stack_redzone test to exit before actual program corruption

Change-Id: I644511ecec8626fe3bdb833bf6bae930fd0fced9
parent 4d78a050
No related branches found
No related tags found
No related merge requests found
......@@ -101,6 +101,5 @@ def get_special_binaries(dls_version: str) -> Set[PpuHwTest]:
expected_exit_code=stack_protection * -559038737),
PpuHwTest(
join(TEST_BINARY_PATH, f"test_stack_redzone_{dls_version}.binary"),
expected_exit_code=stack_redzone * 12,
expect_timeout=not stack_redzone)
expected_exit_code=12 if stack_redzone else 2)
}
#include <stdint.h>
#include "libnux/helper.h"
extern uint8_t stack_redzone;
/*
The stack grows infinitely. With '-fstack-limit-symbol=stack_redzone',
the program exits with error code 12 (= ENOMEM), whereas without this option,
it doesn't finish, since the program memory region gets partially overwritten.
it wouldn't finish, since the program memory region would get partially overwritten, which
is however detected beforehand and a dedicated return value 2 is generated.
*/
int start(void)
int32_t start(void)
{
__attribute__((unused)) int volatile i = 5;
start();
return 0;
uintptr_t stack_ptr;
// return 2 if stack redzone does not work, which is defined here as the stack pointer is
// smaller equal than the stack_redzone symbol location.
// clang-format off
asm volatile (
// load stack pointer
"mr %[stack_ptr], 1\n"
: [stack_ptr] "=r" (stack_ptr) ::
);
// clang-format on
if (stack_ptr < uintptr_t(&stack_redzone)) {
return 2;
}
int x = 5;
do_not_optimize_away(x);
return start();
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment