Re: Why are variables stored on the stack?
- From: santosh <santosh.k83@xxxxxxxxx>
- Date: Sat, 15 Mar 2008 19:56:01 +0530
CJ wrote:
Thanks for all the replies, this is an interesting discussion.
Here are a couple of points that occur to me:
1) Buffer overflows are a more serious security problem on the stack
than on the heap, because the program counter is stored on the stack
and not the heap, so that a malicious stack overflow can execute
arbitrary code. The heap is used for data exclusively, which is what I
meant by "separate data from executable code".
Even if a buffer on the heap overflows, the worst that can happen is
some (probably insignificant) data corruption. Since malloc()
generally allocates space in powers of 2, often an off-by-one error or
similar won't overwrite anything anyway, but will just land in the gap
between the end of the buffer and the next power of 2.
Actually the DieHard framework designed by Emery Berger implements a
similar idea. It randomises the location of heap allocations and tries
to "space them out", so that a small buffer overrun will simply write
to unused memory and not critical data.
See his site for more details:
<http://www.cs.umass.edu/~emery/>
.
- References:
- Prev by Date: Re: Why are variables stored on the stack?
- Next by Date: Re: Why are variables stored on the stack?
- Previous by thread: Re: Why are variables stored on the stack?
- Next by thread: Re: Why are variables stored on the stack?
- Index(es):
Relevant Pages
|