Stack smashing test

A test to check if -fstack-protector can be enabled and is effective.

Ref #3066
This commit is contained in:
Ehmry - 2018-12-05 14:51:34 +01:00 committed by Norman Feske
parent 6819c43a05
commit 5efa6d5273
10 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1 @@
Scenario that immediately tries to write into previous stack frame

View File

@ -0,0 +1,2 @@
_/src/init
_/src/test-stack_smash

View File

@ -0,0 +1 @@
-

View File

@ -0,0 +1,28 @@
<runtime ram="16M" caps="1000" binary="init">
<events>
<timeout meaning="failed" sec="20" />
<log meaning="succeeded">Error: stack protector check failed</log>
</events>
<content>
<rom label="ld.lib.so"/>
<rom label="test-stack_smash"/>
</content>
<config>
<parent-provides>
<service name="LOG"/>
<service name="CPU"/>
<service name="ROM"/>
<service name="PD"/>
</parent-provides>
<default-route>
<any-service> <parent/> </any-service>
</default-route>
<default caps="100"/>
<start name="test-stack_smash">
<resource name="RAM" quantum="4M"/>
</start>
</config>
</runtime>

View File

@ -0,0 +1,2 @@
SRC_DIR = src/test/stack_smash
include $(GENODE_DIR)/repos/base/recipes/src/content.inc

View File

@ -0,0 +1 @@
-

View File

@ -0,0 +1 @@
base

View File

@ -0,0 +1,44 @@
/*
* \brief Simple stack smashing attempt
* \author Emery Hemingway
* \date 2018-12-05
*/
#include <base/component.h>
#include <base/log.h>
#include <util/string.h>
/*
* FIXME
*
* There's a strange optimization implemented in GCC for x86_32 bit using
* __stack_chk_fail_local() which must be a local hidden symbol (and therefore
* part of a static library linked to the target. For more info see
* https://github.com/gcc-mirror/gcc/blob/master/libssp/ssp.c#L195 and
* https://raw.githubusercontent.com/gcc-mirror/gcc/master/gcc/config/i386/i386.c
* line 45261.
*/
extern "C" {
__attribute__((noreturn)) void __stack_chk_fail(void);
extern "C" __attribute__((noreturn)) __attribute__((visibility("hidden")))
void __stack_chk_fail_local(void)
{
__stack_chk_fail();
}
}
void Component::construct(Genode::Env &)
{
using namespace Genode;
char const *msg = "................ wrote into previous frame";
char buf[16];
char *p = buf;
strncpy(p, msg, strlen(msg)+1);
log((char const *)p);
}

View File

@ -0,0 +1,4 @@
TARGET = test-stack_smash
SRC_CC = main.cc
LIBS = base
CC_OPT += -fstack-protector

View File

@ -714,6 +714,7 @@ set default_test_pkgs {
test-signal
test-slab
test-solo5
test-stack_smash
test-stdcxx
test-synced_interface
test-tcp_bulk_lwip