Why Overwriting Saved RIP Hijacks Control
call foostores the legitimate return address on the stack.- Inside
foo, a buffer overflow overwrites that stored address with an attacker-chosen valueX. foofinishes and executesret.retpopsXintoRIP: the CPU now executes atX— shellcode, a libc function, or a ROP chain.
Key Takeaway
The CPU has no idea the return address was tampered with. Control-flow integrity defenses (stack canaries, CFI, shadow stacks) exist precisely to detect this.