mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 13:47:56 +00:00
Stack smashing test
A test to check if -fstack-protector can be enabled and is effective. Ref #3066
This commit is contained in:
parent
6819c43a05
commit
5efa6d5273
1
repos/base/recipes/pkg/test-stack_smash/README
Normal file
1
repos/base/recipes/pkg/test-stack_smash/README
Normal file
@ -0,0 +1 @@
|
||||
Scenario that immediately tries to write into previous stack frame
|
2
repos/base/recipes/pkg/test-stack_smash/archives
Normal file
2
repos/base/recipes/pkg/test-stack_smash/archives
Normal file
@ -0,0 +1,2 @@
|
||||
_/src/init
|
||||
_/src/test-stack_smash
|
1
repos/base/recipes/pkg/test-stack_smash/hash
Normal file
1
repos/base/recipes/pkg/test-stack_smash/hash
Normal file
@ -0,0 +1 @@
|
||||
-
|
28
repos/base/recipes/pkg/test-stack_smash/runtime
Normal file
28
repos/base/recipes/pkg/test-stack_smash/runtime
Normal 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>
|
2
repos/base/recipes/src/test-stack_smash/content.mk
Normal file
2
repos/base/recipes/src/test-stack_smash/content.mk
Normal file
@ -0,0 +1,2 @@
|
||||
SRC_DIR = src/test/stack_smash
|
||||
include $(GENODE_DIR)/repos/base/recipes/src/content.inc
|
1
repos/base/recipes/src/test-stack_smash/hash
Normal file
1
repos/base/recipes/src/test-stack_smash/hash
Normal file
@ -0,0 +1 @@
|
||||
-
|
1
repos/base/recipes/src/test-stack_smash/used_apis
Normal file
1
repos/base/recipes/src/test-stack_smash/used_apis
Normal file
@ -0,0 +1 @@
|
||||
base
|
44
repos/base/src/test/stack_smash/main.cc
Normal file
44
repos/base/src/test/stack_smash/main.cc
Normal 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);
|
||||
}
|
4
repos/base/src/test/stack_smash/target.mk
Normal file
4
repos/base/src/test/stack_smash/target.mk
Normal file
@ -0,0 +1,4 @@
|
||||
TARGET = test-stack_smash
|
||||
SRC_CC = main.cc
|
||||
LIBS = base
|
||||
CC_OPT += -fstack-protector
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user