ROP
acronymKept in this browser · My desk
Stands for: return-oriented programming
Return-oriented programming: an exploitation technique that reuses short sequences of a program's existing instructions, each ending in a return, chained through return addresses the attacker writes on the stack, so that no new code needs to be injected.
ROP is why non-executable memory was not the end of code-execution exploits. Hovav Shacham showed in 2007 that the standard C library contains enough such sequences, many of them never placed there on purpose by the compiler, to compute anything. Intel and Arm now describe ROP in their architecture manuals and answer it in the instruction set, with shadow stacks, pointer authentication, branch target identification and guarded control stacks.
What it is. Return-oriented programming (ROP) builds an attacker's program out of fragments of the victim's own code. Each fragment, a gadget, is a short instruction sequence ending in a return; the attacker writes a chain of gadget addresses onto the stack, and every return pops the next address and jumps there. No new code is injected, so defences that only stop injected code do not stop it. The technique needs a prior memory-corruption bug that lets the attacker control the stack; it is how such a bug is turned into arbitrary computation.
Before ROP: return-into-libc. On 10 August 1997 Solar Designer posted to the Bugtraq list a message titled Getting around non-executable stack (and fix): "I finally decided to post a return-into-libc overflow exploit." Instead of returning into code placed on the stack, the overwritten return address pointed into an existing library function. That showed non-executable stacks were not enough, but it was limited to the functions the library offered.
The idea. A defence called W-xor-X makes memory writable or executable but never both, so injected code cannot run. Shacham's paper, The Geometry of Innocent Flesh on the Bone, presented at the Association for Computing Machinery's Conference on Computer and Communications Security (ACM CCS) in 2007, showed that an attacker who controls the stack can instead chain gadgets: short instruction sequences ending in ret, each return jumping to the next gadget's address. His thesis was a conjecture that in any sufficiently large body of x86 code there will be sequences allowing such gadgets, and he concluded that W-xor-X "is much less useful than previously thought". He found enough gadgets in the standard C library to say that the set "is Turing complete by inspection, so return-oriented programs can do anything possible with x86 code".
Why x86 makes it easy. x86 instructions have no fixed length, so bytes read from an unintended offset decode as other instructions. Shacham's example: f7 c7 07 00 00 00 and 0f 95 45 c3 (a test and a setnz) contain, one byte later, a mov, an xchg, an inc and a ret, the last being the byte c3 of the original operand. The vocabulary is described here at the level of ideas only.
Not only x86, and not only ret. In 2008 Erik Buchanan, Ryan Roemer, Hovav Shacham and Stefan Savage generalized the technique to RISC in When Good Instructions Go Bad (ACM CCS 2008), arguing that the attack was "both more general and a greater threat" than first appreciated, since it did not depend on decoding the middle of variable-length instructions. In 2010 Stephen Checkoway and colleagues from UC San Diego and Ruhr-Universität Bochum showed Return-Oriented Programming without Returns: on x86 and ARM, sequences that "behave like a return" occur often enough in large libraries on Linux and Android to build Turing-complete gadget sets, which defeated defences that watched for too-frequent return instructions.
The defences in silicon. Intel's Software Developer's Manual (SDM) opens its chapter on Control-flow Enforcement Technology (CET) by calling ROP and its CALL/JMP variants "the prevalent attack methodologies for stealth exploit writers"; CET adds a shadow stack, "a second stack for the program that is used exclusively for control transfer operations", against which every RET is checked, and indirect branch tracking with ENDBR64 (F3 0F 1E FA). Arm adds PACIASP, which inserts a pointer authentication code into the return address in X30 using SP as modifier, BTI (branch target identification) for branch targets, and the Guarded Control Stack, introduced in its manual with the sentence that ROP techniques involve changing the return address of procedure calls.
The defences in software. Address space layout randomization (ASLR), as the PaX project designed it, introduces "randomness into addresses used by a given task", so that an attack needing known gadget addresses fails "with a quantifiable probability" and the failed attempts, which usually crash the task, can be detected. The shadow stack needs the whole stack of software to take part. The Linux kernel documentation describes it as "a secondary stack allocated from memory which cannot be directly modified by applications": on CALL the processor pushes the return address to both stacks, on return it compares them and raises a control-protection fault if they differ; user shadow stacks need supporting hardware, a kernel built with X86_USER_SHADOW_STACK, Binutils 2.29 or LLVM 6 or later, and libraries compiled for it. On Windows, the /CETCOMPAT linker option marks an x64 binary as compatible with the CET shadow stack, which Microsoft describes as defending "against return-oriented programming (ROP) based malware attacks". Stack canaries add a check before the corrupted return is used; none of these removes the root cause, which is memory corruption.
What goes wrong. Each defence covers part of the problem: randomization falls to a single leaked address, shadow stacks protect returns but not indirect jumps and calls (hence indirect branch tracking and BTI), and protections that binaries must opt into leave old binaries exposed. Memory-safe languages remove the bug class that makes ROP possible in the first place.
Neighbours. ROP is an exploitation technique for buffer overflows and other memory-corruption bugs, a reply to the no-execute (NX) bit, made harder by ASLR, stack canaries, shadow stacks and pointer authentication, and found with a disassembler that reads machine code from every offset.
Also known as: return-oriented programming, programação orientada a retorno, ROP chain, gadget, return-into-libc
Sources
- Hovav Shacham, The Geometry of Innocent Flesh on the Bone, full version of the ACM CCS 2007 paper (Cornell course copy): gadgets ending in ret, W-xor-X, the English-without-spaces analogy and the f7 c7 07 00 00 00 / 0f 95 45 c3 example (read 2026-11-23)
- Intel SDM 325462-093, Vol. 1, chapter 18 (p. 18-1): ROP and COP/JOP described as the prevalent attack methodologies; the shadow stack and indirect branch tracking; ENDBR64 encoded F3 0F 1E FA (Vol. 2A, p. 3-288) (read 2026-11-23)
- Arm ARM DDI 0487 M.d: PACIASP computes a Pointer Authentication Code for X30 with SP as modifier (C6.2.306, p. C6-2495); BTI (p. C6-1888); the Guarded Control Stack and ROP (section D11.1.1, p. D11-7909) (read 2026-11-23)
- Intel SDM 325462-093: 16 general-purpose registers in 64-bit mode (Vol. 1, p. 3-12); 32-bit results zero-extended to 64 bits (p. 3-13); ZF is bit 6 of EFLAGS (p. 3-16); REX prefixes occupy opcodes 40H to 4FH (Vol. 2A, p. 2-8) (read 2026-11-23)
- Solar Designer, Getting around non-executable stack (and fix), Bugtraq mailing list, 10 August 1997 (Seclists.org archive): the post of a return-into-libc overflow exploit (read 2026-11-23)
- Erik Buchanan, Ryan Roemer, Hovav Shacham and Stefan Savage, When Good Instructions Go Bad: Generalizing Return-Oriented Programming to RISC, ACM CCS 2008 (authors' copy): the attack is more general and a greater threat than first appreciated (read 2026-11-23)
- Stephen Checkoway, Lucas Davi, Alexandra Dmitrienko, Ahmad-Reza Sadeghi, Hovav Shacham and Marcel Winandy, Return-Oriented Programming without Returns (authors' copy): on x86 and ARM, sequences that behave like a return build Turing-complete gadget sets in large libraries on Linux and Android, defeating defences that count returns (read 2026-11-23)
- PaX Team, Address Space Layout Randomization design document (aslr.txt): introduce randomness into the addresses used by a task so that exploit techniques fail with a quantifiable probability and failed attempts can be detected (read 2026-11-23)
- The Linux Kernel documentation, x86, Control-flow Enforcement Technology (CET) Shadow Stack: a secondary stack applications cannot modify; return addresses pushed to both stacks and compared on return, raising a control-protection fault; Kconfig X86_USER_SHADOW_STACK; Binutils 2.29 or LLVM 6 required; arch_prctl ARCH_SHSTK_ENABLE (read 2026-11-23)
- Microsoft Learn, /CETCOMPAT (CET Shadow Stack compatible): the linker option marks a binary as compatible with CET Shadow Stack, which defends against ROP-based malware attacks; x64 only (read 2026-11-23)
- Hovav Shacham, The Geometry of Innocent Flesh on the Bone, full version of the ACM CCS 2007 paper: return-into-libc and Turing completeness among the keywords; the gadget set found in libc is Turing complete by inspection (read 2026-11-23)