3 ms·
You can guarantee undetected stack overflow is impossible if you do two things. First you mprotect() a 4096 byte at the bottom of the stack. Second, you program
by jart 5y ago
You can guarantee undetected stack overflow is impossible if you do two things. First you mprotect() a 4096 byte at the bottom of the stack. Second, you program the compiler to fail if an individual function allocates a stack frame larger than that.
#ifndef STACK_FRAME_UNLIMITED
#pragma GCC diagnostic error "-Wframe-larger-than=4096"
#if __GNUC__ >= 9
#pragma GCC diagnostic error "-Walloca-larger-than=1024"
#pragma GCC diagnostic error "-Wvla-larger-than=1024"
#endif /* GCC 9+ */
#endif /* STACK_FRAME_UNLIMITED */
- alcover 5y agoOh! Now that's an actionable tip. I fail to see the relation between your first measure (which seems to act as a guard?) and the second. Also their sizes don't match. Though I'm afraid I'll encumber this thread with my naive questions.
- nwmcsween 5y agoWhy not mprotect + -fstack-clash-protection?