Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack. (http://www.velocityreviews.com/forums/t703795-c-c-compilers-have-one-stack-for-local-variables-and-return-addresses-and-then-another-stack-for-array-allocations-on-the-stack.html)

Casey Hawthorne 11-01-2009 05:47 PM

C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack.
 
One of the buffer overrun problems seems to be overwriting the return
address on the stack, so as to execute your own code.

C/C++ compilers have one stack for local variables and return
addresses and then another stack for array allocations on the stack.
--
Regards,
Casey

Keith Thompson 11-01-2009 06:53 PM

Re: C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack.
 
Casey Hawthorne <caseyhHAMMER_TIME@istar.ca> writes:
> One of the buffer overrun problems seems to be overwriting the return
> address on the stack, so as to execute your own code.
>
> C/C++ compilers have one stack for local variables and return
> addresses and then another stack for array allocations on the stack.


Was there a "should" missing from that sentence?

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Seebs 11-01-2009 07:07 PM

Re: C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack.
 
On 2009-11-01, Keith Thompson <kst-u@mib.org> wrote:
> Casey Hawthorne <caseyhHAMMER_TIME@istar.ca> writes:
>> One of the buffer overrun problems seems to be overwriting the return
>> address on the stack, so as to execute your own code.
>>
>> C/C++ compilers have one stack for local variables and return
>> addresses and then another stack for array allocations on the stack.


> Was there a "should" missing from that sentence?


This would be a very interesting way to turn a false statement into a
false statement, even assuming we grant semantic coherence.

Since C and C++ compilers often have noticably different ways of
interacting with the environment, it's not necessarily safe to treat
them interchangeably. In particular, I suspect the much more elaborate
range of things that "local variables" contain in C++ creates a substantial
additional risk.

But! There is also the trivia point that a local variable of any type
can have its address taken and be treated as an array of one object of
that type, and I suspect at least some attacks have used that vector. Not
nearly as many, to be sure.

But ultimately, I don't think I buy the argument that this provides
substantial protection. I'm a lot more interested by, say, marking the
stack area as non-executable, which does a pretty good job of solving
things.

Just pragmatically, doing this would dramatically increase implementation
costs, especially on the systems which DO have a native "stack" implemented
by the CPU, because on those systems, keeping track of the second stack would
be much more expensive than keeping track of the first one. Even in
general, though, I don't think this would pay off particularly well.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

Flash Gordon 11-01-2009 08:23 PM

Re: C/C++ compilers have one stack for local variables and returnaddresses and then another stack for array allocations on the stack.
 
Keith Thompson wrote:
> Casey Hawthorne <caseyhHAMMER_TIME@istar.ca> writes:
>> One of the buffer overrun problems seems to be overwriting the return
>> address on the stack, so as to execute your own code.
>>
>> C/C++ compilers have one stack for local variables and return
>> addresses and then another stack for array allocations on the stack.

>
> Was there a "should" missing from that sentence?


Probably.

To the OP (since Keith knows this), the implementation is allowed to
have as many separate stacks (or other structures) for different things
as it likes. Some implementations do clever things to protect against
buffer overflow exploits of this type.
--
Flash Gordon


All times are GMT. The time now is 02:33 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.