Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is Return-Oriented Programming?

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.

Illustration for the cybersecurity term Return-Oriented Programming
Home / Blog / Cybersecurity Terms / What Is Return-Oriented Programming?
17 November 2026

What Is Return-Oriented Programming?

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.

Gadgets and the Stack

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.

What a Chain Is Used For

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.

The Prerequisite Nobody Can Skip

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.

Mitigations That Break the Technique

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.

FAQ – Frequently Asked Questions

Why Can ROP Bypass DEP?

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.

Does ASLR Stop Return-Oriented Programming?

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.

What Is a ROP Gadget?

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.

Does Intel CET Make ROP Impossible?

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.

Related Terms

You May Be Interested In These

What Is a Honeynet?

Cybersecurity Terms

17 November 2026

What Is a Honeynet?

Read More
What Is a Web Shell?

Cybersecurity Terms

17 November 2026

What Is a Web Shell?

Read More
What Is Root and Jailbreak Detection?

Cybersecurity Terms

17 November 2026

What Is Root and Jailbreak Detection?

Read More