tools/nolibc: tests: add test for -fstack-protector
Test the previously introduce stack protector functionality in nolibc. 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>
This commit is contained in:
parent
255ffeee71
commit
9735716830
@ -76,6 +76,9 @@ else
|
|||||||
Q=@
|
Q=@
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
CFLAGS_STACKPROTECTOR = -DNOLIBC_STACKPROTECTOR \
|
||||||
|
$(call cc-option,-mstack-protector-guard=global) \
|
||||||
|
$(call cc-option,-fstack-protector-all)
|
||||||
CFLAGS_s390 = -m64
|
CFLAGS_s390 = -m64
|
||||||
CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables \
|
CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables \
|
||||||
$(call cc-option,-fno-stack-protector) \
|
$(call cc-option,-fno-stack-protector) \
|
||||||
|
@ -667,6 +667,63 @@ int run_stdlib(int min, int max)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
__attribute__((optnone))
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
__attribute__((optimize("O0")))
|
||||||
|
#endif
|
||||||
|
static int smash_stack(void)
|
||||||
|
{
|
||||||
|
char buf[100];
|
||||||
|
|
||||||
|
for (size_t i = 0; i < 200; i++)
|
||||||
|
buf[i] = 'P';
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int run_protection(int min, int max)
|
||||||
|
{
|
||||||
|
pid_t pid;
|
||||||
|
int llen = 0, status;
|
||||||
|
|
||||||
|
llen += printf("0 -fstackprotector ");
|
||||||
|
|
||||||
|
#if !defined(NOLIBC_STACKPROTECTOR)
|
||||||
|
llen += printf("not supported");
|
||||||
|
pad_spc(llen, 64, "[SKIPPED]\n");
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pid = -1;
|
||||||
|
pid = fork();
|
||||||
|
|
||||||
|
switch (pid) {
|
||||||
|
case -1:
|
||||||
|
llen += printf("fork()");
|
||||||
|
pad_spc(llen, 64, "[FAIL]\n");
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
case 0:
|
||||||
|
close(STDOUT_FILENO);
|
||||||
|
close(STDERR_FILENO);
|
||||||
|
|
||||||
|
smash_stack();
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
default:
|
||||||
|
pid = waitpid(pid, &status, 0);
|
||||||
|
|
||||||
|
if (pid == -1 || !WIFSIGNALED(status) || WTERMSIG(status) != SIGABRT) {
|
||||||
|
llen += printf("waitpid()");
|
||||||
|
pad_spc(llen, 64, "[FAIL]\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
pad_spc(llen, 64, " [OK]\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* prepare what needs to be prepared for pid 1 (stdio, /dev, /proc, etc) */
|
/* prepare what needs to be prepared for pid 1 (stdio, /dev, /proc, etc) */
|
||||||
int prepare(void)
|
int prepare(void)
|
||||||
{
|
{
|
||||||
@ -719,8 +776,9 @@ int prepare(void)
|
|||||||
/* This is the definition of known test names, with their functions */
|
/* This is the definition of known test names, with their functions */
|
||||||
static const struct test test_names[] = {
|
static const struct test test_names[] = {
|
||||||
/* add new tests here */
|
/* add new tests here */
|
||||||
{ .name = "syscall", .func = run_syscall },
|
{ .name = "syscall", .func = run_syscall },
|
||||||
{ .name = "stdlib", .func = run_stdlib },
|
{ .name = "stdlib", .func = run_stdlib },
|
||||||
|
{ .name = "protection", .func = run_protection },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user