A buffer overflow attack occurs when more data is written to a buffer than it is designed to hold. This excess data can overwrite adjacent memory locations, leading to the execution of malicious code or crashing the system. Buffer overflows are a common vulnerability that attackers exploit to gain unauthorized access to systems.