0

In an answer to How do ASLR and DEP work? Polynomial says:

In a non-ASLR and non-DEP process, the stack address is the same every time we run the process. We know exactly where it is in memory.

I don't understand how that could be. Isn't RAM allocated dynamically at run time? What about when the program (X) exits and another process comes along (Y)? Could'nt the OS give (Y) that RAM at the same location?

Steffen Ullrich
  • 184,332
  • 29
  • 363
  • 424
james6125
  • 211
  • 1
  • 8
  • This is actually not a question about security but how computers and modern OS work. And it is also not about ASLR because you ask about the case where ASLR is not done. I think if you read about the concept [virtual memory](https://en.wikipedia.org/wiki/Virtual_memory) you understand why all processes can have the same memory layout from the view of the process. Apart from that, please give proper credit when citing somebody instead of doing a verbatim quoting but giving the source as "I've heard". – Steffen Ullrich May 13 '17 at 05:51
  • Thanks for the comments and links Steffen!! Outstanding resource as usual!!! – james6125 May 13 '17 at 14:25

1 Answers1

2

Addresses that you are seeing through your debugging tool are logical memory addresses. Every time a program is spawned, the CPU allocates certain bytes of memory to the program. On the hardware, this may be allocated in one single chunk or it may be strewn over in parts all over the place. However, to make it simpler for the program to refer to memory locations, the CPU maps these hardware or physical memory address to logical address.

A program interacting within this address space does not see other programs. Only the CPU knows which physical address to fetch when the program refers to some logical memory address within the code.

So, two different programs can refer to the same logical memory location, say 0x7c900000. But the CPU knows where to point this instruction to on the physical RAM. This makes life simpler for the programmer when memory management is taken care of by the CPU.

About ASLR (Adress Space Layout Randomization):

ASLR was introduced because it was fairly easy to reach the exact point in memory during program execution to find buffer overflow vulnerable variables. This made writing exploits easy. ASLR randomized the placement of variables making it difficult for hackers to exploit buffer overflow vulnerabilities.

So without ASLR, the variables in your program and instructions are going to be loaded in the exact same (logical) locations every time you execute it.

Amey
  • 284
  • 1
  • 2