The VikiD Truth

Knowledge base / Computing / Computer science, theory & data

Computing | Computer Security | Linux Security | Industrial Control Systems Security | Penetration Testing | Exploitation | Social Engineering | Metasploit | encryption | IDS/IPS | HoneyPots | Securing Web/Apps | Stacks

Stacks

eip
    |
    | EBP
    |
    |_
    |
    | OLD EBP
    |_
    |
    | DATA
    |_
    |
    | DATA
ebp |

The ebp is the entry point to the data on the stack.

Buffer Overflows

The plain idea

The call stack is the scratchpad a program uses to keep track of function calls. Every time a function is called, the machine pushes a stack frame onto the stack: a block holding that function’s local variables, its arguments, and, crucially, the return address, where to jump back to when the function finishes. When the function returns, its frame is popped off. My diagram traces the two registers that manage this: EBP (the base/frame pointer, marking the current frame) and EIP (the instruction pointer, the return address saved on the stack).

Why it matters

This page sits in the security section for one reason: the stack’s layout is the target of the most famous class of exploit in history, the buffer overflow. If a program writes more data into a local buffer than it has room for, the extra data spills over the neighbouring slots, including that saved return address. Overwrite the return address and you can make the program jump wherever you like, including into code you supplied. Understanding the stack is understanding how exploitation works at the metal.

An everyday analogy: a stack of sticky notes

Imagine doing a task that interrupts itself. You are cooking (write a note: “return to stirring”), then you answer the phone (new note on top: “return to cooking”), then the doorbell rings (another note on top). You always deal with the top note first and remove it, returning exactly to where you left off. The return address is “where was I?”, written down so you never lose your place. A buffer overflow is someone sneaking in and rewriting your bottom note so you “return” somewhere you never meant to go.

A worked example: the overflow

void vulnerable(char *input) {
    char buffer[8];          // room for 8 bytes
    strcpy(buffer, input);   // copies with NO length check
}

Call vulnerable with 8 bytes and all is well. Call it with 50 bytes and strcpy keeps writing past buffer, over the saved EBP, and over the return address above it on the stack. Craft those overflow bytes carefully and the return address now points at attacker-chosen code. That is the classic “smashing the stack” attack.

A 2026 update

Decades of defences have made this far harder, though not impossible:

The arms race continues, but “don’t use unbounded copies like strcpy/gets” remains rule number one.

Common misconceptions

How it connects

The truth revealed: the stack is just a tidy pile of “where was I?” notes, and almost all of low-level hacking is the art of rewriting the one note at the bottom.

Last edited · 2 revisions

Tags: #Computing