Temporal errors
Main types:
- use after free
- uninitialized variables
Use after free
Sometimes, program retains pointer to freed memory location (“dangling pointer”)
- e.g. malloc buffer that was freed, or local variable buffer after function return
Future allocation/function call can re-use memory.
Sometimes, attacker can craft input to overwrite memory with own data:
- Program allocs buffer or variable X
- Program uses X to store some data
- Program frees X
- Program allocates buffer/variable Y overlapping with X
- Data written to Y also overwrites relevant part of X
- Program uses X, causing incorrect result
Useful to:
- bypass length restrictions for later buffer overflow
- overwrite fields that shouldn’t be attacker-controlled
- overwrite validated data with incorrect data that will not be validated
- leak sensitive data from new buffer
Double free
Free can’t efficiently check block validity
- detects only some cases of double free
- undetected cases might corrupt metadata, useful for arbitrary write
- might free reused memory
Uninitialized variables
Local variables and buffers not automatically initialized to zero.
Instead, contain whatever data happened to be on stack/heap before they were allocated.
Sometimes, attacker can craft input to initialize variable;
- program allocates buffer/variable X
- program uses X to store some data under attacker control
- program frees X
- program allocs buffer/variable Y overlapping X
- program does not initialize (part of) Y, causing attacker’s data from X to remain there
- program uses Y causing incorrect result