LEAVE
By Vesper Vei
1 minute read
Table of Contents
LEAVE (leave)
Basic purpose
LEAVE is used to restore the stack frame from before a function call, equivalent to cleaning up local variables and restoring the old RBP. Equivalent behavior:
mov rsp, rbppop rbpInstruction execution process
- Write the value of RBP into RSP (discard the local variable area)
- Pop the old RBP from the stack
Instruction format
leaveBehavioral characteristics
- Single-byte instruction
- A common epilogue before a function returns
- Shorter and faster than writing the two instructions manually when cleaning up a stack frame
- In overflows: when the saved RBP has been overwritten,
leaveassigns that “fake RBP” to RSP
Common uses
- Standard function tail:
push rbp→ … →leave - Very clear for debugging stack frames
- In PWN, RBP can be forged to hijack the destination of the subsequent RET