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

Re: [MiNT] Safe stack overflow




On Mon, Feb 24, 2014 at 10:20 PM, Markus Fröschle <markus@mubf.de> wrote:
Hmmm. I don’t get it.
Typical TPA looks like this:

<heap>
<stack>
<bss segment>
<data segment>
<text segment> 

Text segments lies on the lowest address, stack on the highest. Now, if a stack overflow occurs, bss and data gets overwritten. If you rearrange it like this:

<heap>
<bss segment>
<data segment>
<text segment> 
<stack>

as soon as the SP leaves the program's allocated and protected area => boom, memory violation.

You could of course use memory protection to protect the stack, but that probably would only need slight changes to your program, not necessarily to MiNT: just put the stack into a malloc’d region and make sure you don’t own adjacent memory below.
Yes, this could work too but it's more complex and fragments memory.

--
MiKRO / Mystic Bytes
http://mikro.atari.org