Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Encoding Return Address and Stack Pointer
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Casey Hawthorne  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 04:38
Newsgroups: comp.lang.c
From: Casey Hawthorne <caseyhHAMMER_T...@istar.ca>
Date: Sat, 07 Nov 2009 20:38:14 -0800
Local: Sun 8 Nov 2009 04:38
Subject: Encoding Return Address and Stack Pointer
Making the stack area non-executable will not help against stack based
buffer overruns, since the return address could be changed to an
executable area of memory.

A solution could be that the C compiler is setup so that when a
function call is made, it is set up to encode the return address
placed on the stack with the stack pointer (SP) and possibly some fast
encryption technique.
Then if the return address is altered, when the return address is
unencoded/decrypted and found to be invalid, the application would
stop with an invalid return address message sent back to the O/S.  

I realize this would eat up quite a few cycles, so it would be better
if it was done in hardware.

Tail Call Optimization (TCO) would still work, since no additional
stack frames are pushed on the stack, so the return address would not
be altered.
--
Regards,
Casey


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gene  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 04:50
Newsgroups: comp.lang.c
From: Gene <gene.ress...@gmail.com>
Date: Sat, 7 Nov 2009 20:50:01 -0800 (PST)
Local: Sun 8 Nov 2009 04:50
Subject: Re: Encoding Return Address and Stack Pointer
On Nov 7, 11:38 pm, Casey Hawthorne <caseyhHAMMER_T...@istar.ca>
wrote:

It would be far simpler to keep return addresses on a separate stack
that's inaccessible from any pointer within a data frame.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BGB / cr88192  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 05:16
Newsgroups: comp.lang.c
From: "BGB / cr88192" <cr88...@hotmail.com>
Date: Sat, 7 Nov 2009 22:16:30 -0700
Local: Sun 8 Nov 2009 05:16
Subject: Re: Encoding Return Address and Stack Pointer

"Casey Hawthorne" <caseyhHAMMER_T...@istar.ca> wrote in message

news:sqacf5phnhk9m9nmm9hjiqv4f757ea9e5d@4ax.com...

this is OT here but:
Linux uses the trick of randomizing load addresses, locations for allocated
memory, ... in this way, overflowing the stack and getting ar the return
address will be unable to readily produce usable results, since on each run
of an app the memory layout is different.

even if the return address/... were mangled, one would still need a
randomized feature for it to be effective, and it would cost in terms of
performance, ...

randomized load addresses are, thus, much cheaper, just not as ideal on
Windows since it would then requiring rebasing DLLs on load, which reduces
Windows ability to use shared memory for them.

a possible option (if implemented in the OS), would be to essentially ignore
the default load address, and instead re-assign the DLL to some randomized
address on a per-boot basis (or periodically for longer-running systems).
this could still allow a moderate level of memory sharing (since the DLLs
would be largely rebased in a manner consistent between running processes).

similarly, it could actually improve the situation considering how often
DLL's tend to use the "default" load address, it could actually cause them
to be rebased more consistently.

some level of randomization WRT the heap layout, locations of the stack, ...
also makes sense.

the one downside is that with 32-bit processes, this does notably increase
the risk of unusably fragmenting the address space if full randomness is
allowed, but an "ordered random" strategy is less likely to produce good
levels of chaos.

but at least it could shuffle them around in memory, which may be worthwhile
in its own right.

a related thick could be "turbulent indeterminism" where, in cases where a
full random pattern is not usable, things are fudged such that some level of
"chaos" is added, such that no 2 runs (and maybe no 2 builds) have exactly
the same memory layout.

or such...


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William Ahern  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 05:34
Newsgroups: comp.lang.c
From: William Ahern <will...@wilbur.25thandClement.com>
Date: Sat, 7 Nov 2009 21:34:19 -0800
Local: Sun 8 Nov 2009 05:34
Subject: Re: Encoding Return Address and Stack Pointer

Casey Hawthorne <caseyhHAMMER_T...@istar.ca> wrote:
> Making the stack area non-executable will not help against stack based
> buffer overruns, since the return address could be changed to an
> executable area of memory.

But often the code area is non-writable, which OpenBSD brands as W^X. So
exploits are initially--see mmap()--limited to the consequences of malformed
data

> A solution could be that the C compiler is setup so that when a
> function call is made, it is set up to encode the return address
> placed on the stack with the stack pointer (SP) and possibly some fast
> encryption technique.
> Then if the return address is altered, when the return address is
> unencoded/decrypted and found to be invalid, the application would
> stop with an invalid return address message sent back to the O/S.  

Many general purpose system compilers these days by default use stack
canaries to detect these attempts. To overwrite the return address you'll
usually have to overwrite the canary, which is verified on return. GCC reads
randomness at startup and employs this; whether it XOR's w/ the return
address--simpe encryption--or uses some other scheme, I'm unsure.

> I realize this would eat up quite a few cycles, so it would be better
> if it was done in hardware.

IIRC, ProPolice incurred a cost less than 5%, and this is what ultimately
went into GCC mainline.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gordon Burditt  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 21:38
Newsgroups: comp.lang.c
From: gordonb.sy...@burditt.org (Gordon Burditt)
Date: Sun, 08 Nov 2009 15:38:12 -0600
Local: Sun 8 Nov 2009 21:38
Subject: Re: Encoding Return Address and Stack Pointer

>Making the stack area non-executable will not help against stack based
>buffer overruns, since the return address could be changed to an
>executable area of memory.

Yes, but what's *IN* that area of memory?  If the policy is that
executable memory is not writable, you can only run malicious
code that's already loaded.  Granted, functions like remove() will
probably be present, and you might be able to give them an argument
of your choosing.  It still limits the nastiness a lot.

>A solution could be that the C compiler is setup so that when a
>function call is made, it is set up to encode the return address
>placed on the stack with the stack pointer (SP) and possibly some fast
>encryption technique.

I think that's way overkill.  You'd probably get a lot more from
randomized load addresses.  Also, if you managed to put some
non-writable memory in each stack frame (I think Electric Fence
does something like this, not necessarily for stack variables),
attempts at overruns would segfault.  This might have a cost of the
minimum size stack frame for a function being 4K.

>Then if the return address is altered, when the return address is
>unencoded/decrypted and found to be invalid, the application would
>stop with an invalid return address message sent back to the O/S.  

You might be able to alter saved registers to make a routine do
something nasty, *WITHOUT* changing the return address.  This is
much harder to do, but in certain cases it's possible.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google