Re: Silent stack-heap collision under GNU/Linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2014-07-20 12:04:43 -0700, Ian Lance Taylor wrote:
> On Sun, Jul 20, 2014 at 10:49 AM, Vincent Lefevre
> <vincent+gcc@xxxxxxxxxx> wrote:
> > It appears that GCC can generate code that yields silent stack-heap
> > collision under GNU/Linux. I mean, the program doesn't crash (at least
> > not immediately), the memory just gets corrupted. At the same time,
> > this overrides the stack-size limit defined at the kernel level
> > (getrlimit system call / RLIMIT_STACK) because the kernel has no
> > chance to detect the collision (no page fault); thus this limit
> > doesn't protect the user, and the problem seems to be on GCC's side.
> >
> > Why aren't such collisions detected by default?
> 
> Because it's expensive,
[...]

Really? This takes only a few instructions, doesn't it? And AFAIK,
the detection is needed only when the stack pointer decrement is
important (the problem occurs only when unmapped memory after the
stack is skipped). In most cases, VLA's are not used and GCC should
be able to determine an upper bound on the stack pointer decrement,
thus avoiding generating this detection on functions that don't need
it.

> > How can one tell GCC to detect them?
> 
> Use the -fstack-check option.
[...]

Thanks, I hadn't tried this one.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux