diff --git a/repos/base/recipes/pkg/test-stack_smash/README b/repos/base/recipes/pkg/test-stack_smash/README new file mode 100644 index 0000000000..0a2daa2c36 --- /dev/null +++ b/repos/base/recipes/pkg/test-stack_smash/README @@ -0,0 +1 @@ +Scenario that immediately tries to write into previous stack frame diff --git a/repos/base/recipes/pkg/test-stack_smash/archives b/repos/base/recipes/pkg/test-stack_smash/archives new file mode 100644 index 0000000000..e62e7b61c5 --- /dev/null +++ b/repos/base/recipes/pkg/test-stack_smash/archives @@ -0,0 +1,2 @@ +_/src/init +_/src/test-stack_smash diff --git a/repos/base/recipes/pkg/test-stack_smash/hash b/repos/base/recipes/pkg/test-stack_smash/hash new file mode 100644 index 0000000000..39cdd0ded6 --- /dev/null +++ b/repos/base/recipes/pkg/test-stack_smash/hash @@ -0,0 +1 @@ +- diff --git a/repos/base/recipes/pkg/test-stack_smash/runtime b/repos/base/recipes/pkg/test-stack_smash/runtime new file mode 100644 index 0000000000..ac5e16c3bd --- /dev/null +++ b/repos/base/recipes/pkg/test-stack_smash/runtime @@ -0,0 +1,28 @@ + + + + + Error: stack protector check failed + + + + + + + + + + + + + + + + + + + + + + + diff --git a/repos/base/recipes/src/test-stack_smash/content.mk b/repos/base/recipes/src/test-stack_smash/content.mk new file mode 100644 index 0000000000..88f3deffda --- /dev/null +++ b/repos/base/recipes/src/test-stack_smash/content.mk @@ -0,0 +1,2 @@ +SRC_DIR = src/test/stack_smash +include $(GENODE_DIR)/repos/base/recipes/src/content.inc diff --git a/repos/base/recipes/src/test-stack_smash/hash b/repos/base/recipes/src/test-stack_smash/hash new file mode 100644 index 0000000000..39cdd0ded6 --- /dev/null +++ b/repos/base/recipes/src/test-stack_smash/hash @@ -0,0 +1 @@ +- diff --git a/repos/base/recipes/src/test-stack_smash/used_apis b/repos/base/recipes/src/test-stack_smash/used_apis new file mode 100644 index 0000000000..df967b96a5 --- /dev/null +++ b/repos/base/recipes/src/test-stack_smash/used_apis @@ -0,0 +1 @@ +base diff --git a/repos/base/src/test/stack_smash/main.cc b/repos/base/src/test/stack_smash/main.cc new file mode 100644 index 0000000000..352a1af0e3 --- /dev/null +++ b/repos/base/src/test/stack_smash/main.cc @@ -0,0 +1,44 @@ +/* + * \brief Simple stack smashing attempt + * \author Emery Hemingway + * \date 2018-12-05 + */ + +#include +#include +#include + + +/* + * 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); +} diff --git a/repos/base/src/test/stack_smash/target.mk b/repos/base/src/test/stack_smash/target.mk new file mode 100644 index 0000000000..47be65ee0d --- /dev/null +++ b/repos/base/src/test/stack_smash/target.mk @@ -0,0 +1,4 @@ +TARGET = test-stack_smash +SRC_CC = main.cc +LIBS = base +CC_OPT += -fstack-protector diff --git a/repos/gems/run/depot_autopilot.run b/repos/gems/run/depot_autopilot.run index 939cf932ad..b878d603dc 100644 --- a/repos/gems/run/depot_autopilot.run +++ b/repos/gems/run/depot_autopilot.run @@ -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