Top 3 Runtime Protections C/C++ Uses Against Buffer Overflows

C/C++ programs often rely on runtime mitigations like Address Space Layout Randomization (ASLR) to randomize memory locations, Data Execution Prevention (DEP) to mark memory as non-executable, and stack canaries to detect stack-based overflows before they are exploited, though these are not foolproof.

The top 3

  1. Stack Canaries: Sentinel Values Protecting Return Addresses: Stack canaries place a secret value between local buffers and sensitive data on the stack; if this value is modified during runtime, it indicates a buffer overflow, leading to program termination.
  2. Data Execution Prevention (DEP): Blocking Malicious Code Execution: DEP marks memory areas as non-executable, preventing attackers from running injected malicious code from data regions like the stack or heap, effectively nullifying many buffer overflow exploits.
  3. ASLR: Randomizing Memory Layouts to Thwart Exploits: Address Space Layout Randomization (ASLR) shuffles the memory addresses of executable code, libraries, stack, and heap, making it significantly harder for attackers to predict target locations for buffer overflow exploits.

Sources

Open the full topic