Stack Smashing: When a Memory Write Damages What Comes Next
Stack smashing happens when a program writes data past the edge of a reserved space in memory and damages what's next to it. The affected space, called a buffer, sits on the program's stack.
The stack holds information used by active function calls. A function is a named unit of work inside a program. Stack smashing is also called a stack-based buffer overflow: the write crosses the buffer's boundary.
Memory outside the buffer already has other jobs. If the program writes there, it may damage data or information that controls what the program does next.
When a Program Writes Past the End of Its Memory
The neighboring memory determines the harm
Suppose a function reserves a buffer to hold some incoming data. If its copying operation checks the available space correctly, oversized input can be rejected or handled safely. If it copies beyond that space, the extra bytes—small units of digital data—overwrite something outside the buffer.
That is a buffer overflow. For stack smashing, the affected buffer is on the stack.
Nearby information may include a return address, which tells the program where to resume execution when the function finishes. Corrupting that information can change the path through the program. Other overwritten locations may produce a crash or damage ordinary data instead.
MITRE's stack-based buffer overflow description covers these outcomes and their limits. The layout varies, so an overflow doesn't invariably reach a return address. Even unauthorized code execution happens within the circumstances and privileges of the affected program, rather than automatically giving an attacker control of the entire machine.
A crash is therefore evidence of failure, not proof of a successful takeover. Long input isn't proof of an attack either; the invalid write is the defect that needs explaining.
- Understand how exploits really work instead of just running someone else's tool.
- Practice safely in the Linux environment that comes with the book, away from your own system.
- Build the C and assembly foundation that serious security research rests on.
Using up stack space through too many nested function calls is stack exhaustion, a different failure. It runs out of space rather than writing beyond a stack buffer and damaging neighboring memory.
Why a protective stop can be deliberate
Development tools can add checks that detect some stack corruption. A compiler, which translates program code for execution, can place a guard value in selected functions and check it when the function exits.
If that guard has changed, the program may stop with an error instead of continuing with damaged memory. The GNU Compiler Collection's stack-protector documentation describes this behavior.
The coverage depends on the selected protection and the code being built. A guard doesn't catch every possible overwrite, and detecting corruption doesn't repair the instruction that caused it. The protective stop also interrupts the application's work.
The repair belongs in the code that writes the data: it has to check the available space and keep the write inside it.
Buffer Overflow: How a Memory Mistake Becomes an Attack

Remote Code Execution: When Input Becomes Instructions

Input Validation Attacks: When Software Accepts the Wrong Data

QUOTE:
"Amateurs hack systems, professionals hack people."
