[llvm-bugs] [Bug 26122] New: Safe-stack leaks stack with dynamic alloca
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Jan 12 13:14:17 PST 2016
https://llvm.org/bugs/show_bug.cgi?id=26122
Bug ID: 26122
Summary: Safe-stack leaks stack with dynamic alloca
Product: libraries
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Miscellaneous Instrumentation passes
Assignee: unassignedbugs at nondot.org
Reporter: kuba.brecka at gmail.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Safe-stack instrumentation seems to wrongly handle some dynamic alloca cases.
Here's a test case that crashes when -fsanitize=safe-stack is used on it. We
seem to forget to reset the unsafe stack pointer when leaving the function,
causing a stack leak and eventually overrunning the unsafe stack.
#include <alloca.h>
#include <stdio.h>
void f() {
for (int i = 0; i < 10; i++) {
int *p = alloca(4096);
*p = 42;
}
}
int main(int argc, const char * argv[]) {
printf("Hello, World!\n");
for (int i = 0; i < 10000000; i++) {
f();
}
return 0;
}
Disassembly:
f:
0x100000ed0 <+0>: pushq %rbp
0x100000ed1 <+1>: movq %rsp, %rbp
0x100000ed4 <+4>: movl $0x0, -0x4(%rbp)
0x100000edb <+11>: cmpl $0xa, -0x4(%rbp)
0x100000edf <+15>: jge 0x100000f1d ; <+77> at
safe-stack-alloca-crash.c:9
0x100000ee5 <+21>: movq %gs:0x80, %rax
0x100000eee <+30>: addq $-0x1000, %rax
0x100000ef4 <+36>: andq $-0x10, %rax
0x100000ef8 <+40>: movq %rax, %gs:0x80
0x100000f01 <+49>: movq %rax, -0x10(%rbp)
0x100000f05 <+53>: movq -0x10(%rbp), %rax
0x100000f09 <+57>: movl $0x2a, (%rax)
0x100000f0f <+63>: movl -0x4(%rbp), %eax
0x100000f12 <+66>: addl $0x1, %eax
0x100000f15 <+69>: movl %eax, -0x4(%rbp)
0x100000f18 <+72>: jmp 0x100000edb ; <+11> at
safe-stack-alloca-crash.c:5
0x100000f1d <+77>: popq %rbp
0x100000f1e <+78>: retq
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160112/77038a56/attachment.html>
More information about the llvm-bugs
mailing list