Address Space Layout Randomization (ASLR) is a memory protection mechanism that defends against buffer overflow attacks by randomizing where data is stored in RAM each time it is written. This prevents attackers from reliably targeting specific memory locations to execute malicious code.
ASLR Overview
Another thing that's preconfigured on your machines nowadays is this address space layout randomization, or ASLR.
ASLR has to do with memory — memory as in RAM on your computer. This right here is a stick of RAM, and we've got some data that's written inside of RAM. So essentially anything that gets processed on your machine will be sent to RAM, and then RAM will send it to the CPU. The CPU will process it, store it back into RAM, and then it will send it to wherever it needs to go.
ASLR starts out with AS. The AS stands for address space. So what is address space? Well, we need to be able to write to this memory and be able to take information out of this memory, or extract information from this memory, and be able to manipulate and control this. Because of that, we need to address certain blocks of data within here. The way we do that is with addressing. So all of this is broken into small pieces here, and they're labeled with some sort of address, and we use that address to access that piece of memory.
We also have something called a buffer. A buffer is going to be a place that we're going to store information in. So for instance, let's say I type my name in here into some sort of application. It needs to store that somewhere. It needs to keep track — I've typed it in there for a reason. Since it needs to store it somewhere, it will store it within memory. Well, it stores it within what's called a buffer. A buffer is a piece of memory that we use to store variables in.
There is this thing called buffer overflow. We allot a certain size for these buffers, and if we add too much information to the buffer, then it overflows the buffer and writes over other pieces of information. So this is called buffer overflow.
We don't need to be concerned too much with heap or stack, but just know that there are parts that we write to as part of the heap and there are parts that we write to as part of the stack, and there are buffers in each one of those. The heap and the stack is going to be where this issue falls into play.
Since a stack buffer overflow is more common, let's take a look at that side of it. Here's a buffer right here. This is where we're going to write information. It has some sort of address space — that is the address space location of where it starts — and then it's allocated a certain size to it. If you overwrite that, or if it overflows, it's going to write into these other fields here.
Now, this could be utilized for a certain type of attack. We call it a buffer overflow attack. So what does that look like? Well, normally, if I were to enter my name in here, Andrew, it would go into the buffer, it would be stored, and whenever it needs to access that, then it could access that and pull it. And then once it accesses that, it uses this return value to return back to whatever memory allocation it needs to return back to, whatever address space it needs to then go back and reference. That's the way to go back to the primary way that it's executing this code. You don't need to be too involved in that.
But what can happen here is that instead of putting my name Andrew in there, I could put some sort of code in this buffer instead. Now, normally it wouldn't execute this code and it wouldn't be problematic. I could put this code into this buffer, but it's just going to try to use it in some other way, and it's probably not going to make sense and it's going to error out. But what happens if I can overflow to write over this return address and return it back to this address? Now, instead of just grabbing that information and using that information, it's actually going to execute that information. And since it's code now that I slipped in there, it's going to execute that code and I can compromise the system.
Now, a key part in carrying out this attack is that I need to know where this address space is right here. Where's the beginning of the buffer? Because what I need to do is form whatever my input is going to be, so that it comes directly to this return address right here and it will return to that address space right there. So it needs to be very specific, what I type into here. This whole process really relies on this address.
So now let's get back to this name, address space layout randomization, ASLR. What does it mean? Address space — here's the address space. We talked about that address space. We talked about the importance of this buffer and returning to that buffer. So what is the layout randomization? It means that every time I enter something into this value right here, it's actually going to store it in a different address location. It's going to take this buffer and move it somewhere else, and so this address is going to change. If this address keeps changing, then I can't figure out what to put in this return address in order for it to execute the code that I want to do. So what address space layout randomization does is it stops buffer overflow attacks from happening. It mitigates this issue.
TechKnowSurge builds IT and cybersecurity professionals through hands-on, concept-first training built around real understanding — not memorization. Free interactive tools, structured programs, and 25+ years of real-world experience, all in one place.
Explore free tools and programs →