Advanced Topic 41 of 51 Security & Cryptography
ASLR and Stack Canaries
Mitigations randomizing layout and detecting stack corruption.
How it works
Address space layout randomization randomizes where the stack, heap, libraries and executable are loaded in memory on each run, so an attacker cannot know the addresses of useful code or data. Stack canaries are secret values placed between local buffers and the saved return address; the function checks them before returning, and a changed canary shows a stack overflow and aborts the program. Together with non-executable stacks and position-independent executables they raise the cost of memory-corruption exploits.
Where it is used
Modern operating systems and compilers enable them by default, for example the GCC stack protector options and Windows and Linux ASLR.
Common pitfall
They are mitigations, not fixes: information leaks reveal addresses and defeat ASLR, canaries can be leaked or bypassed by overwriting other data, and 32-bit systems have little randomness. Non-PIE binaries and old libraries remain predictable. Fix the underlying bug, compile with hardening flags and combine layers.
Where it fits in the course
ASLR and Stack Canaries is topic 41 of 51 in Security & Cryptography, rated Advanced. It follows Return-Oriented Programming. The next topic is Sandboxing.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Security & Cryptography quiz.
- Explore the Stack, Queue & Linked List visualizer: Push, pop, enqueue and dequeue interactively.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Security & Cryptography quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is ASLR and Stack Canaries?
Where do people use ASLR and Stack Canaries?
What is the most common mistake with ASLR and Stack Canaries?
What should I learn before this topic?
How can I practice it?
Is ASLR and Stack Canaries hard to learn?
How long does it take to learn ASLR and Stack Canaries?
Which topics are related to ASLR and Stack Canaries?
What should I study after ASLR and Stack Canaries?
Related topics
- Return-Oriented Programming (Security & Cryptography)
- Sandboxing (Security & Cryptography)
- Side-Channel Attacks (Security & Cryptography)
- Trusted Execution Environments (Security & Cryptography)
- Stack vs Heap (Languages & Compilers)
- Call Stack (Programming Fundamentals)