Menu

1 / 4

Memory Corruption, All the Way Down to the Register

DEV Community: cpp·Harrison Guo·about 3 hours ago
#BmKCr47U
#devtocpp#devto#dev#address#stack
Reading 0:00
15s threshold

A CPU does not know what your program meant. It knows one thing well. It has a register, the instruction pointer, that holds the address of the next instruction. On x86-64 it is called RIP. The machine fetches the instruction at RIP, decodes it, runs it, advances RIP, and repeats. That loop is the whole computer.

Memory corruption is the art of deciding what goes into that register. Everything else, every overflow and every freed pointer, is plumbing to reach it. If you understand the register, you understand why this entire class of bug exists and why it has been the most valuable one for thirty years.

Why it is even possible

Two facts from the ground floor, and the rest follows.

Code and data share one space. This is the von Neumann design, and it is not an accident you can patch. The stack that holds your local char buf[64] also holds the return address that will become RIP when the function finishes. They sit inches apart in the same flat array of bytes.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.