use-after-free

term

programmingsecurityhacking

Using a pointer to memory that has already been released, back when it still meant something.

The pointer is now dangling: the allocator may have handed that block to something else entirely, so the program is reading or writing another object's data through the wrong lens. It is more dangerous than a plain crash because the contents are attacker-influenceable if they can control what gets allocated into the freed space, which makes it a mainstay of modern browser and kernel exploitation, and the reason double-free is treated as its sibling. Defenses are ownership discipline, setting pointers to null after freeing, hardened allocators, and ultimately languages that make the pattern unrepresentable. It is CWE-416.

Use after free accesses memory that has already been released, at which point the allocator may have handed it to something else. The danger is not the read itself but that an attacker who controls what gets allocated into that space controls what the stale pointer now points at.

It is harder to reason about than an overflow because the bug and its consequence are separated in time and often in code. Sanitizers find it during testing by delaying reuse and poisoning freed regions, hardened allocators make exploitation less reliable, and neither eliminates it. It is the most common serious memory bug in modern C and C++ codebases, which is much of the reason for the ownership models in newer languages.

Also known as: UAF, dangling pointer, CWE-416

All glossary entries