EMZETT.
Login

Buffer overflow and protections (ASLR, stack canary, DEP)

In short: A buffer overflow occurs when a program writes more data into a memory area than fits, overwriting neighbouring data. Modern systems make exploitation harder through several layers of protection.

In more detail: Typical in languages without automatic bounds checking such as C and C++. What can be overwritten are variables or the return address on the stack.

In Depth

  • Cause: Functions such as strcpy or gets do not check length. Safer are strncpy/snprintf, length checks or languages with bounds checking (Rust, Java, Python).
  • Stack canary: A secret value before the return address is checked before the function returns. If it differs, the program aborts.
  • DEP/NX: Data areas are not executable, injected code does not run.
  • ASLR: Addresses of stack, heap and libraries change on every start, so fixed jump targets are missing.
  • More: Control-flow integrity (CFI), compiler warnings, sanitizers (see Valgrind and sanitizers), fuzzing.
  • Long term: Memory-safe languages prevent the whole class of problems.

See also: Exploit