Add simple runtime tests for shadowcallstack
Summary:
ShadowCallStack does not yet have a runtime provided by compiler-rt, but
this change includes simple tests that make use of a very minimal
runtime in test/shadowcallstack/minimal_runtime.h
Reviewers: pcc, kcc, delcypher, eugenis, filcab
Reviewed By: pcc
Subscribers: kubamracek, mgorny, delcypher, llvm-commits, #sanitizers, kcc
Differential Revision: https://reviews.llvm.org/D44803
llvm-svn: 329210
2018-04-05 01:53:33 +08:00
|
|
|
// A shadow call stack runtime is not yet included with compiler-rt, provide a
|
2018-04-10 04:18:10 +08:00
|
|
|
// minimal runtime to allocate a shadow call stack and assign an
|
|
|
|
// architecture-specific register to point at it.
|
Add simple runtime tests for shadowcallstack
Summary:
ShadowCallStack does not yet have a runtime provided by compiler-rt, but
this change includes simple tests that make use of a very minimal
runtime in test/shadowcallstack/minimal_runtime.h
Reviewers: pcc, kcc, delcypher, eugenis, filcab
Reviewed By: pcc
Subscribers: kubamracek, mgorny, delcypher, llvm-commits, #sanitizers, kcc
Differential Revision: https://reviews.llvm.org/D44803
llvm-svn: 329210
2018-04-05 01:53:33 +08:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
|
2018-04-10 04:18:10 +08:00
|
|
|
#include "libc_support.h"
|
Add simple runtime tests for shadowcallstack
Summary:
ShadowCallStack does not yet have a runtime provided by compiler-rt, but
this change includes simple tests that make use of a very minimal
runtime in test/shadowcallstack/minimal_runtime.h
Reviewers: pcc, kcc, delcypher, eugenis, filcab
Reviewed By: pcc
Subscribers: kubamracek, mgorny, delcypher, llvm-commits, #sanitizers, kcc
Differential Revision: https://reviews.llvm.org/D44803
llvm-svn: 329210
2018-04-05 01:53:33 +08:00
|
|
|
|
|
|
|
__attribute__((no_sanitize("shadow-call-stack")))
|
|
|
|
static void __shadowcallstack_init() {
|
|
|
|
void *stack = mmap(NULL, 8192, PROT_READ | PROT_WRITE,
|
|
|
|
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
|
|
|
if (stack == MAP_FAILED)
|
|
|
|
abort();
|
|
|
|
|
2019-03-08 02:56:36 +08:00
|
|
|
#if defined(__aarch64__)
|
2018-04-10 04:18:10 +08:00
|
|
|
__asm__ __volatile__("mov x18, %0" ::"r"(stack));
|
|
|
|
#else
|
|
|
|
#error Unsupported platform
|
|
|
|
#endif
|
Add simple runtime tests for shadowcallstack
Summary:
ShadowCallStack does not yet have a runtime provided by compiler-rt, but
this change includes simple tests that make use of a very minimal
runtime in test/shadowcallstack/minimal_runtime.h
Reviewers: pcc, kcc, delcypher, eugenis, filcab
Reviewed By: pcc
Subscribers: kubamracek, mgorny, delcypher, llvm-commits, #sanitizers, kcc
Differential Revision: https://reviews.llvm.org/D44803
llvm-svn: 329210
2018-04-05 01:53:33 +08:00
|
|
|
}
|
|
|
|
|
2018-04-10 04:18:10 +08:00
|
|
|
int scs_main(void);
|
|
|
|
|
|
|
|
__attribute__((no_sanitize("shadow-call-stack"))) int main(void) {
|
|
|
|
__shadowcallstack_init();
|
|
|
|
|
|
|
|
// We can't simply return scs_main() because scs_main might have corrupted our
|
|
|
|
// return address for testing purposes (see overflow.c), so we need to exit
|
|
|
|
// ourselves.
|
|
|
|
exit(scs_main());
|
|
|
|
}
|