WCU / Cybersecurity
~/CSC 472/Class 02/KP 08
Class 02 · KP 08 / 23

Function Prologue and Epilogue

higher addressessaved return addresshijack targetsaved RBPchar buffer[ ]local variablelower addresses (RSP)overflowwrites up
A stack frame: overflowing the buffer overwrites the saved return address.

A typical callee sets up a frame on entry and tears it down on exit:

foo:
    push rbp            ; save caller's frame pointer
    mov  rbp, rsp       ; establish new frame base
    sub  rsp, 0x20      ; reserve 32 bytes for locals
    ...                 ; function body (locals at [rbp-8], ...)
    leave               ; mov rsp, rbp ; pop rbp
    ret                 ; pop return address into RIP
  • RBP anchors local variables and arguments at fixed offsets.
  • leave restores the caller frame; ret returns control.