Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
Return-oriented programming builds a payload from short instruction sequences that already exist in a program, chaining them through the stack to execute arbitrary logic without injecting any new code.

What Is Return-Oriented Programming?
When Data Execution Prevention made injected shellcode unrunnable, exploitation did not stop; it changed shape. Return-oriented programming assembles a payload entirely from code that is already loaded and already executable. The attacker never writes a single new instruction. They write a list of addresses, and the processor obediently walks it.
A gadget is a short sequence of instructions ending in a ret. On x86, pop rdi; ret loads a value into a register and returns. mov [rax], rbx; ret writes memory. Dozens of useful gadgets exist in any reasonably sized binary, and because x86 instructions are variable length, gadgets can also be found by jumping into the middle of an intended instruction, which yields sequences the compiler never emitted.
The stack is the program counter for the chain. After a buffer overflow overwrites the saved return address, the first ret transfers control to the first gadget. That gadget executes, hits its own ret, and pops the next address the attacker placed on the stack. Each gadget does a little work and hands over, so a sequence of fragments performs arbitrary computation. Hovav Shacham formalised this in 2007 with the paper that gave the technique its name, proving the gadget set in a standard C library was Turing complete.
Where the overflow is not on the stack, the chain starts with a stack pivot: a gadget such as xchg rsp, rax; ret that points the stack pointer at attacker-controlled memory, usually on the heap.
In practice, nobody builds a full program out of gadgets. The chain is short and has one objective: undo the mitigation. The usual target is a call to VirtualProtect on Windows or mprotect on Linux that marks a region of attacker-controlled memory as executable, after which conventional shellcode runs normally. Setting up such a call means loading arguments into the right registers, which is precisely what a handful of pop gadgets provide.
The technique has relatives. Jump-oriented programming uses gadgets ending in indirect jumps rather than returns, driven by a dispatcher gadget instead of the stack. Call-oriented programming uses indirect calls. Sigreturn-oriented programming on Linux abuses the signal return mechanism to restore an entire register set from attacker-controlled memory in one step. All exist to work around specific defences.
Tooling is mature and freely available: ROPgadget, ropper, and the angrop module in angr enumerate gadgets and in many cases assemble a working chain automatically. Finding gadgets is no longer the hard part of exploitation.
A chain is a list of absolute addresses, so the attacker must know where the gadgets are. That makes ASLR the control that actually matters, and it also explains why serious exploits are nearly always two bugs: one that leaks an address and one that corrupts memory. A single module compiled without position independence, loading at a fixed address, supplies the anchor on its own and renders the randomisation of everything else irrelevant.
ret raises a fault, which terminates a ROP chain at the first gadget.The lesson for defenders is unglamorous: compile with the flags, enable the processor features, and keep third-party binaries in scope. Our Penetration Test Services include binary hardening reviews that report exactly which modules in your estate ship without CET, CFG, or ASLR support.
Because it never introduces new code. Data Execution Prevention stops the processor executing instructions from pages marked as data, which blocks injected shellcode. A return-oriented programming chain executes only instructions that are already in memory and already marked executable, within the program binary or its libraries, so no policy is violated. The attacker controls the order of execution, not the code.
It is the main obstacle, because a chain consists of absolute addresses that must be known in advance. Attackers defeat it by pairing the memory corruption bug with an information disclosure that leaks one address from the target module, which reveals the whole module layout. A single binary loaded at a fixed address also defeats it, which is why every module needs position-independent builds.
A short sequence of machine instructions that ends in a return, found in code that is already loaded. Typical examples load a register from the stack, move data between registers, or write to memory. Because x86 instructions vary in length, gadgets can also be formed by decoding from the middle of a longer instruction, producing sequences the compiler never intended to emit.
It makes classic stack-based chains fail, because the shadow stack holds a protected copy of each return address and a mismatch triggers a fault. Attackers respond by shifting to jump-oriented and call-oriented techniques that do not rely on returns, which is why indirect branch tracking and control flow integrity are needed alongside it. The combination is strong; either alone is partial.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.