Implement protection against the stack clash attack [0] through inline stack
probing.
Probe stack allocation every PAGE_SIZE during frame lowering or dynamic
allocation to make sure the page guard, if any, is touched when touching the
stack, in a similar manner to GCC[1].
This extends the existing `probe-stack' mechanism with a special value `inline-asm'.
Technically the former uses function call before stack allocation while this
patch provides inlined stack probes and chunk allocation.
Only implemented for x86.
[0] https://www.qualys.com/2017/06/19/stack-clash/stack-clash.txt
[1] https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00556.html
This a recommit of 39f50da2a3 with proper LiveIn
declaration, better option handling and more portable testing.
Differential Revision: https://reviews.llvm.org/D68720
23 lines
660 B
C
23 lines
660 B
C
// Check the correct function attributes are generated
|
|
// RUN: %clang_cc1 -triple x86_64-linux -O0 -S -emit-llvm -o- %s -fstack-clash-protection | FileCheck %s
|
|
|
|
// CHECK: define void @large_stack() #[[A:.*]] {
|
|
void large_stack() {
|
|
volatile int stack[20000], i;
|
|
for (i = 0; i < sizeof(stack) / sizeof(int); ++i)
|
|
stack[i] = i;
|
|
}
|
|
|
|
// CHECK: define void @vla({{.*}}) #[[A:.*]] {
|
|
void vla(int n) {
|
|
volatile int vla[n];
|
|
__builtin_memset(&vla[0], 0, 1);
|
|
}
|
|
|
|
// CHECK: define void @builtin_alloca({{.*}}) #[[A:.*]] {
|
|
void builtin_alloca(int n) {
|
|
volatile void *mem = __builtin_alloca(n);
|
|
}
|
|
|
|
// CHECK: attributes #[[A]] = {{.*}} "probe-stack"="inline-asm"
|