RET
By Vesper Vei
1 minute read
Table of Contents
RET (ret)
Basic purpose
RET pops the return address from the top of the stack and jumps to it; it is the exit instruction used when a function finishes execution. Equivalent behavior:
pop ripImmediate version:
ret 8Equivalent to:
pop ripadd rsp, 8Used by calling conventions to clean up arguments.
Instruction execution process
- Read the return address from RSP and assign it to RIP
- Increase RSP by 8 (x64)
Instruction format
retret imm16Behavioral characteristics
-
The jump target is determined entirely by the stack contents
-
Does not modify EFLAGS
-
Is the core trampoline of ROP attacks
-
If the return address is overwritten, program control flow is hijacked
Common uses
- Function return
- Gadgets in a ROP chain
- Constructing attack patterns such as ret2libc and ret2plt
- Implementing lightweight jumps in shellcode