Smashing the Stack
Abstract
On 8 November 1996 the hacker magazine Phrack published issue 49. File 14 of 16, 66 kilobytes long, was “Smashing The Stack For Fun And Profit” by Aleph One, the handle of Elias Levy, who moderated the Bugtraq mailing list. The paper explained, for anyone with basic knowledge of assembly language, why a C program that copies input into a fixed-size buffer without checking its length can be made to run code of the attacker’s choosing. The flaw was old: the Morris Worm had used it in 1988. What changed in 1996 was that the knowledge moved from a few specialists into a public text. By 2000, academics called the buffer overflow “the vulnerability of the decade,” and the defences built against it between 1997 and 2007 (stack canaries, non-executable memory, and address space layout randomization) remain standard in mainstream operating systems.
Before Phrack 49
The buffer overflow comes from a design choice in C (see Dennis Ritchie and the C Language). Arrays carry no length, and standard library functions such as gets() and strcpy() copy until they reach the end of their input, whatever the size of the destination. In a running program, a function’s local variables sit on the stack next to the bookkeeping that tells the processor where to continue when the function returns. Input that is longer than its buffer spills into that bookkeeping.
The first famous case was the Internet worm of November 1988. One of its three methods of spreading sent an over-long request to the fingerd daemon, the service that answered queries about who was logged in (see Robert Tappan Morris). The technique was then known to the people who had analysed the worm, and to few others.
In the mid-1990s the knowledge began to circulate in writing. On 13 February 1995 Thomas Lopatic posted “Vulnerability in NCSA HTTPD 1.3” to Bugtraq: the web server his group ran on an HP 9000/720 under HP-UX 9.01 could be made to execute commands, and he noted that the bug was similar to the fingerd bug the worm had used. On 20 October 1995 Peiter Zatko (“Mudge”) of the Boston group L0pht wrote “How to write Buffer Overflows.” It opened: “This is really rough, and some of it is not needed.” He wrote it, he said, as a note to himself, because he did not want to read AT&T-syntax assembly again and was afraid of forgetting what he had worked out.
Phrack Issue 49
Phrack, an underground electronic magazine, had published the Mentor’s “Conscience of a Hacker” in 1986 (see The Hacker Culture). Issue 49 was edited by daemon9, Datastream Cowboy, and Voyager. Aleph One’s file opened with a credit line (“BugTraq, r00t, and Underground.Org bring you”) and an epigraph: the Jargon File’s entry for “smash the stack,” which defines it as writing past the end of a local array so that the function’s return jumps to a random address.
The introduction set out its purpose in one sentence: “This paper attempts to explain what buffer overflows are, and how their exploits work.” It named the reason for writing it now: over the previous months, overflows had been found in syslog, splitvt, sendmail 8.7.5, the Linux and FreeBSD mount command, the Xt library, and at. It assumed an Intel x86 processor and Linux, and stated the one prerequisite: “Basic knowledge of assembly is required.”
What followed was a textbook chapter. It explained how a process’s memory is organised, what a stack is and why compilers use one, and how a function call lays out its data, before it reached the overflow itself. Earlier write-ups had described individual bugs in individual programs. Aleph One described a general method that applied to any program with the same kind of mistake, worked through it from first principles, and added appendices for Linux on i386 and for Solaris and SunOS on SPARC. A reader who finished it could look at a C program and see whether it was vulnerable.
That was the point on both sides. Administrators and programmers learned to recognise the pattern in their own code; the same readers could recognise it in other people’s. The academic literature cited it as the reference for the technique: the StackGuard group listed it in their 2000 survey of the field, alongside the Bugtraq list that Aleph One ran.
Aleph One and Bugtraq
Bugtraq, founded by Scott Chasin in November 1993, was the main venue for full disclosure: researchers posted vulnerability details, often with working proof-of-concept code, on the theory that vendors fixed only what the public could see (see The Vulnerability Disclosure Debate). From about the end of 1995, by his own count, Levy moderated the list, reading and approving its traffic nearly every day.
He later co-founded SecurityFocus and was its chief technology officer; Bugtraq had moved to SecurityFocus in 1999. On 15 October 2001 he posted “Administrivia: So Long, and Thanks for All the Fish”: “I have been moderating Bugtraq nearly continuously on a daily basis for almost six years now,” he wrote, and he named David Ahmad as the new moderator. Symantec completed its acquisition of SecurityFocus on 6 August 2002.
The Vulnerability of the Decade
The years after 1996 bore out the paper’s opening observation. In 2000 Crispin Cowan and his colleagues at the Oregon Graduate Institute presented “Buffer Overflows: Attacks and Defenses for the Vulnerability of the Decade” at DARPA’s DISCEX conference in Hilton Head, South Carolina. Their first sentence: “Buffer overflows have been the most common form of security vulnerability for the last ten years.” Nine of the thirteen CERT advisories of 1998 had involved buffer overflows, and at least half of those of 1999.
The largest internet worms of the next three years used the same class of bug. On 18 June 2001 the security firm eEye disclosed a buffer overflow in Microsoft’s IIS web server, and Microsoft released a patch on 26 June. The Code Red worm began exploiting it on 12 July; on 19 July a second version infected more than 359,000 computers in less than 14 hours, according to the measurements by David Moore, Colleen Shannon, and Jeffery Brown at CAIDA. On 25 January 2003 the Slammer worm (also called Sapphire) used a buffer overflow in Microsoft SQL Server. It was 376 bytes long, doubled the number of infected hosts every 8.5 seconds, and infected more than 90 percent of the vulnerable machines within ten minutes, at least 75,000 hosts. Code Red struck six months before Bill Gates’s Trustworthy Computing memo of January 2002, described in Secure by Design.
Canaries, Non-Executable Stacks, and Random Addresses
The defences came in three families, each aimed at one step of the attack Aleph One had described.
The first was to detect the overflow before it took effect. Crispin Cowan’s group at the Oregon Graduate Institute presented StackGuard at the 7th USENIX Security Symposium in San Antonio, 26 to 29 January 1998, “a simple compiler technique that virtually eliminates buffer overflow vulnerabilities.” It was a patch to the GCC compiler that placed a known value, a “canary,” next to the return address and checked it before the function returned; a changed canary meant the stack had been overwritten, and the program stopped. By the time of the 2000 survey the group had run a StackGuard-compiled Red Hat Linux 5.1 on their own machines for more than a year. Microsoft’s C++ compiler adopted the same idea as the /GS switch, which is now on by default.
The second was to stop injected data from running as code. The programmer Solar Designer published a Linux kernel patch that made the stack non-executable. On 10 August 1997 he posted “Getting around non-executable stack (and fix)” to Bugtraq, showing that an attacker could still redirect a program into code already present in the C library, a technique called return-into-libc; he credited Pavel Machek with having discussed the idea on the linux-kernel list months earlier. The PaX project, whose original design document for non-executable pages is dated November 2000, extended the principle to all memory: no page should be both writable and executable. OpenBSD shipped this rule, under the name W^X, in version 3.3 on 1 May 2003, at first on SPARC, Alpha, and HP PA-RISC machines. AMD and Intel added a per-page execute-disable bit (NX and XD) to their processors, and Microsoft turned the protection on as Data Execution Prevention in Windows XP Service Pack 2, released to manufacturing on 6 August 2004.
The third was to make addresses unpredictable, since every attack needed to know where in memory its target lay. PaX implemented address space layout randomization (ASLR) as a patch for the Linux kernel. OpenBSD 3.4, released on 1 November 2003, loaded shared libraries in random order and, on i386, at partly randomized addresses, and Linux 2.6.12, released on 17 June 2005, randomized the start of each process’s stack and of its memory-mapped area. Microsoft announced ASLR for Windows Vista in May 2006: a program library could now load at any of 256 locations, so a guess had a 1 in 256 chance of being right.
Return-Oriented Programming
Each defence closed one route and left others open. Solar Designer’s return-into-libc had already shown in 1997 that an attacker did not need to inject code if useful code was already in memory, but the technique was long considered limited to calling whole library functions. In 2007 Hovav Shacham of the University of California, San Diego, showed at the ACM Conference on Computer and Communications Security that short fragments of existing machine code, each ending in a return instruction, could be chained into arbitrary computation. He called it, “facetiously,” return-oriented programming, and concluded that the widely deployed W⊕X defence was “much less useful than previously thought.”
The mitigations raised the cost of turning a memory bug into a working attack. They did not remove the bugs. Microsoft reported in 2019 that memory-safety errors were the root cause of about 70 percent of the vulnerabilities it fixed and assigned a CVE number, the same class that Phrack 49 had described. The response that followed was to change the language rather than guard the stack, through memory-safe languages such as Rust (see Rust and Memory Safety) and the US government’s 2024 call to adopt them.
📚 Sources
- Aleph One: “Smashing The Stack For Fun And Profit,” Phrack 7(49), file 14 of 16, 8 November 1996 (credit line, epigraph, introduction, x86/Linux assumption, list of recent overflows)
- Phrack issue 49, introduction and table of contents (release date 1996-11-08, editors, 66 K file size)
- The Mentor: “The Conscience of a Hacker,” Phrack 1(7), phile 3, written 8 January 1986, issue released 25 September 1986
- Bugtraq archive, 1993 (first month: November 1993)
- Bugtraq, Wikipedia (finding aid: founded by Scott Chasin on 5 November 1993, moved to SecurityFocus in July 1999)
- Lopatic, Thomas: “Vulnerability in NCSA HTTPD 1.3,” Bugtraq, 13 February 1995
- Mudge (Peiter Zatko): “How to write Buffer Overflows,” L0pht Heavy Industries, 20 October 1995 (mirror at insecure.org)
- Levy, Elias: “Administrivia: So Long, and Thanks for All the Fish,” Bugtraq, 15 October 2001 (almost six years as moderator, David Ahmad successor)
- SecurityFocus, Wikipedia (finding aid: Levy as co-founder and CTO, Symantec acquisition completed 6 August 2002)
- Cowan, Crispin et al.: “StackGuard: Automatic Adaptive Detection and Prevention of Buffer-Overflow Attacks,” 7th USENIX Security Symposium, San Antonio, 26–29 January 1998 (patch to gcc)
- Cowan, Crispin; Wagle, Perry; Pu, Calton; Beattie, Steve; Walpole, Jonathan: “Buffer Overflows: Attacks and Defenses for the Vulnerability of the Decade,” DARPA Information Survivability Conference and Exposition (DISCEX 2000), Hilton Head, South Carolina (CERT figures for 1998 and 1999, Red Hat 5.1 StackGuard, citation of Aleph One)
- Moore, David; Shannon, Colleen; Brown, Jeffery: “Code-Red: a case study on the spread and victims of an Internet worm,” CAIDA, 2002 (eEye disclosure, patch date, 359,000 hosts in under 14 hours)
- Moore, David; Paxson, Vern; Savage, Stefan; Shannon, Colleen; Staniford, Stuart; Weaver, Nicholas: “The Spread of the Sapphire/Slammer Worm,” CAIDA, 2003 (376 bytes, 8.5-second doubling, 90 percent in ten minutes, 75,000 hosts)
- Solar Designer: “Getting around non-executable stack (and fix),” Bugtraq, 10 August 1997
- PaX Team: ASLR design document
- PaX documentation index (original PAGEEXEC design document dated 16 November 2000)
- OpenBSD 3.4 release page, 1 November 2003 (random library order, randomized addresses on i386, ProPolice)
- OpenBSD 3.3 release page, 1 May 2003 (W^X, architectures)
- Linux 2.6.12, Kernel Newbies (released 17 June 2005, address space randomization)
- Microsoft: “Microsoft Releases Windows XP Service Pack 2 with Advanced Security Technologies to Computer Manufacturers,” 6 August 2004
- Howard, Michael: “Address Space Layout Randomization in Windows Vista,” Microsoft blog, 26 May 2006 (256 locations)
- Microsoft Learn: /GS (Buffer Security Check), on by default
- Shacham, Hovav: “The Geometry of Innocent Flesh on the Bone: Return-into-libc without Function Calls (on the x86),” 14th ACM CCS, October 2007 (W⊕X history, NX/XD, XP SP2, Solar Designer credit) and full version (PDF)
- Microsoft Security Response Center: “We Need a Safer Systems Programming Language,” July 2019