Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize native image memory location on Linux #4268

Closed
JohnChen0 opened this issue May 21, 2015 · 9 comments
Closed

Optimize native image memory location on Linux #4268

JohnChen0 opened this issue May 21, 2015 · 9 comments
Milestone

Comments

@JohnChen0
Copy link

Currently on Linux, the native image for mscorlib (mscorlib.ni.dll) is loaded at a memory location far away from CoreCLR (libcoreclr.so). Since these two modules are over 2GB apart, all transitions between them have to go through indirect jumps. This creates a small performance penalty. CoreCLR should be modified to optimize where it loads native images.

@JohnChen0 JohnChen0 self-assigned this May 21, 2015
@kangaroo
Copy link
Contributor

We should be careful here. There are security tradeoffs. Do we want to ASLR native images?

I would vote yes.

@masonwheeler
Copy link
Contributor

@kangaroo I've never actually seen a good explanation of how ASLR does anything to truly improve security.

Without ASLR: Attacker knows that TARGET_FUNCTION is located at address 0xABCDEF00, so he writes his attack code to jump to 0xABCDEF00.

With ASLR: Attacker doesn't know where TARGET_FUNCTION is located, because its location is no longer hard-coded. But in order for the program that links against TARGET_FUNCTION to be able to access it, it has to have a lookup in a hard-coded location that says where TARGET_FUNCTION is located. So that lookup is located at 0xFEDCBA00, and all the attacker has to do is write his attack code to use an indirect jump to the address found at 0xFEDCBA00. Unless the attacker is really squeezed for bytes... how does ASLR keep him out?

I've been asking this question for years now and never heard a good answer. Is there one?

@kangaroo
Copy link
Contributor

@masonwheeler At a super quick explanation level: How does the attacker know that the PLT is at 0xFEDCBA00? Generally ASLR bypass requires walking from a controlled pointer to a vtable, or some other data structure with a known offset from the PLT. Additionally, more advanced ASLR can consider to reorder segments or PLT entries, etc to avoid that static constant offset.

@masonwheeler
Copy link
Contributor

@kangaroo Sure, you can move things around, but at some point something has to exist at a static, known location, or pre-compiled code can't access it. And once that entry point exists... well, it's the same as the reason why DRM has never worked and never can: if a machine can read it, so can a programmer who can read machine code.

Am I missing something? I'll be the first to admit there's plenty I don't know, but as I understand it, ASLR doesn't actually put any mitigation in an attacker's path; it just throws around some indirections that act as speed-bumps. It feels to me more like "application security theatre" than "application security".

@kangaroo
Copy link
Contributor

@masonwheeler Why does something have to exist at a static known location that persists between execution runs. The runtime linker can fix this for you. Does this mean that ASLR cannot be bypassed? No, but it does introduce a non-trivial amount of extra work to find an ASLR bypass. Of course this rapidly starts delving into the topic of ASLR applied to many things (segments, libraries, heaps, stacks), and is likely out of the scope of this specific issue.

That said, there is a non-academic reason why every major OS implements ASLR, and is actively trying to improve on it from release to release. CFI, SMAP, SMEP and other technologies probably throw up more effective barriers, but security is an onion.

Given CoreCLR has a server target focus, making 1 exploit that goes from $sp+[constant] to get to a ROP chain to gain execution would be very, very bad. We need careful consideration around issues like this.

Perhaps someone from the MS security team would like to chime in?

cc @richlander @jkotas @janvorli @sergiy-k

@janhenke
Copy link
Member

I agree with @kangaroo. We should really support security technologies provided by the platform we are running on. Certainly there is no "perfect" security, but everything making it harder for an attacker is certainly something good.

@DemiMarie
Copy link

Just because mscorelib is near CoreCLR does not mean that the two need to be in the same relative location every time. Also, mscorelib is mostly verifiable managed code.

@gkhanna79
Copy link
Member

@sergiy-k Is this still outstanding?

@sergiy-k
Copy link
Contributor

This should be fixed by dotnet/coreclr#3218.

@JohnChen0 JohnChen0 removed their assignment May 19, 2016
@msftgits msftgits transferred this issue from dotnet/coreclr Jan 30, 2020
@msftgits msftgits added this to the 1.0.0-rtm milestone Jan 30, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants