JMU
Buffer Overflows in C
Vulnerabilities, Attacks, and Mitigations


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Getting Started
Vulnerabilities when Using Arrays - Length Faults
Vulnerabilities when Using Arrays - Length Faults (cont.)
Vulnerabilities when Using Arrays - Sentinel Faults
Vulnerabilities when Using Strings
Vulnerabilities when Using Strings - gets()
Vulnerabilities when Using Strings - strcpy()
Vulnerabilities when Using Strings - strcat()
Vulnerabilities when Using Strings - sprintf()
Vulnerabilities when Using Strings - Null Termination
Vulnerabilities when Using Strings - Null Termination (cont.)

An Example

char     a[10], b[10];

strncpy(a, "0123456789", 10); // a will not be null-terminated

strcpy(b, a);                 // b will probably overflow
  
Threats - Memory Corruption
Threats - Arbitrary Memory Writes
Threats - Corrupted Function Pointers
Threats - Stack Smashing
Attacks - Data Integrity
Attacks - Data Integrity (cont.)
Attacks - Program Termination/Availability
An Example
cexamples/bufferoverflow/smash.c