In 1988, Robert Morris Jr. wrote a worm that exploited a buffer overflow in the fingerd daemon’s gets() call, and it took down something like 10% of the internet’s connected machines in a day. The bug was embarrassingly simple: fingerd read input into a fixed-size buffer with no bounds checking, so a crafted request could overwrite the return address on the stack and redirect execution into attacker-supplied shellcode. There was no canary, no ASLR and no NX bit. The stack was writable and executable, and the return address sat right there to be overwritten.
Almost forty years later we still see buffer overflows in CVE feeds every week, but exploitation looks very different now because stack canaries, ASLR and NX/DEP ship by default on nearly every mainstream OS. None of them fix the underlying bug class. They raise the cost of exploitation, sometimes a lot and sometimes only a little, so it helps to know where each one stops.
Stack canaries are tripwires, not fences

A stack canary is a known value placed between local buffers and the saved return address/frame pointer on the stack, written at function entry and checked at function exit. If a buffer overflow overwrites it on the way to clobbering the return address, the check fails before the function returns and the process dies loudly instead of jumping to attacker-controlled code.
Mechanically, on glibc/GCC, the canary value comes from a per-process random value stored in the thread control block (accessible via the %fs segment on x86-64, specifically fs:0x28). The prologue of a protected function does something like:
mov rax, fs:0x28
mov [rbp-8], rax ; stash canary on stack
and the epilogue reloads it and compares:
mov rax, [rbp-8]
xor rax, fs:0x28
jnz __stack_chk_fail
If the XOR isn’t zero, the stored value was changed, meaning something wrote past its intended buffer, and __stack_chk_fail() gets called. That function doesn’t try to recover. It prints something like “* stack smashing detected *” and calls abort(), which raises SIGABRT. It fails fast on purpose, because you can’t negotiate with a corrupted stack.
What canaries protect against specifically: sequential buffer overflows that overwrite the canary before reaching the return address. That’s a narrower category than “stack overflow” sounds. They do nothing for:
– Overflows that use a format string bug or an arbitrary write primitive to hit the return address directly without touching the canary
– Overflows in a different memory region entirely, heap, BSS, a global function pointer
– Information leaks that read the canary value first, then write a matching value back (this is the standard bypass once you have an arbitrary-read primitive, since the canary is constant for the life of the process, only randomized at process start, not per-call)
– Thread-local races where a leaked canary from one thread gets reused against another, if the attacker can pivot
So a canary catches one common shape of overflow. It’s cheap (a few instructions per call) and it stops the “smash the return address with a long string” attack that made the Morris worm easy. It is not a memory-safety guarantee.
ASLR randomizes, it doesn’t prevent
Address Space Layout Randomization randomizes the base addresses of the stack, heap, shared libraries, and (with PIE binaries) the executable itself, at process load time. The idea: even if an attacker has a working exploit that redirects execution, they don’t know where anything useful lives in memory, so they can’t point to it.
Entropy sources vary by platform and region. On 64-bit Linux, mmap’d regions (including shared libraries) get randomized within a range that’s typically 28-30 bits of entropy depending on kernel config, giving you roughly 2^28 possible base addresses. The stack gets somewhat less, historically around 2^24-2^28 bits of usable entropy after accounting for how addresses get used. Heap randomization is weaker still on many systems. None of these numbers are secure in the cryptographic sense. They make brute-force guessing impractical in a reasonable number of attempts, not impossible.
ASLR is probabilistic, not absolute, and a few things follow from that:
1. Brute force is viable against fork-happy daemons. If a service forks a new child per connection without re-randomizing (classic case: Apache’s mod_php on some old configs, or earlier Linux implementations before fork-based ASLR fixes), an attacker can just guess repeatedly. Each failed guess might crash the child, but the parent keeps forking new ones with the same layout. The 2009 “Heap Feng Shui” era and various Apache/PHP remote exploits used exactly this pattern, fork-and-retry until the guess lands.
2. 32-bit systems have far less entropy (roughly 8 bits of usable randomization for mmap in some configs), making brute force practical in seconds rather than requiring days.
3. Information leaks defeat ASLR completely, no guessing required. This is the dominant bypass in modern exploitation. If an attacker can read even one pointer, a leaked stack address from an uninitialized variable, a libc address disclosed via a format string bug, a heap pointer printed in an error message, they can compute the base of the containing region (since offsets within a loaded module are fixed, only the base is randomized) and derive the address of literally anything else in that same module. ASLR fails as a unit: leak one address in libc, you have all of libc.
That’s why so much modern exploit development is “find a memory disclosure bug, then a corruption bug” instead of one bug doing everything. ASLR didn’t stop exploitation. It turned “overwrite and jump” into “leak, compute, then overwrite and jump.”
NX/DEP: write or execute, not both
NX (No-eXecute, called DEP on Windows) marks memory pages as either writable or executable, never both, the W^X principle. Stack and heap memory, which an attacker can write shellcode into, gets marked non-executable. The CPU enforces this at the hardware level via a bit in the page table entry (the NX bit on x86, XN on ARM), so even if execution somehow jumps into attacker-controlled data, the processor refuses to fetch instructions from that page and faults instead.
This single-handedly killed the classic “overflow the buffer, put shellcode in the buffer, redirect return address to the buffer” attack that worked against fingerd in 1988. You can’t do that on a properly configured modern system. That specific technique is dead.
What it does not stop: reusing existing executable code already mapped in memory. That’s return-oriented programming (ROP). Instead of injecting new code, the attacker chains together short existing instruction sequences ending in ret (called gadgets), already present in the binary or libc, each one doing a small piece of useful work (pop a register, call a function, set up arguments) before “returning” into the next gadget. The stack holds a sequence of addresses instead of shellcode, and the CPU is just executing legitimate, already-mapped, already-executable code the entire time. NX doesn’t care, because no new executable memory was ever introduced. A classic ROP chain redirects into libc’s system() function with a controlled argument, achieving the same “spawn a shell” result the Morris worm got, just via a completely different mechanical path. Return-to-libc attacks predate even the term ROP and were already circumventing early NX deployments in the early 2000s.
Where this leaves us
Layer all three together and the 1988 fingerd attack doesn’t work anymore in its original form: the canary catches the naive overflow, NX stops shellcode injection even if you dodge the canary, and ASLR means you don’t know where libc or the stack live even if you’re trying to build a ROP chain. That’s real progress.
But plenty is left. Heap exploitation (use-after-free, double-free, heap metadata corruption) is barely touched by any of these three, canaries are a stack-only mechanism, and heap corruption routes around them entirely. ROP and its descendants (JOP, COOP for C++ vtables) route around NX by construction. And ASLR’s entire security model collapses the moment there’s an info leak, which is why modern CVEs so often chain a disclosure bug with a corruption bug rather than relying on one or the other alone. Control-Flow Integrity, stack clash protections and Intel CET’s shadow stack exist because the three classic mitigations were never a complete answer. They are worth having, and they set a much higher bar than the one Robert Morris cleared in 1988.

Leave a Reply
You must be logged in to post a comment.