A buffer overflow occurs when a program or process tries to store more data in a buffer (temporary data storage area) than it was intended to hold.
Buffer overflow attacks depend on two things: the lack of boundary testing and a machine that can execute code that resides in the data/stack segment.
Buffer Overflows vulnerability can be detected by skilled auditing of the code as well as boundary testing.
Once the stack is smashed the attacker can deploy his payload and take control of the attacked system.
Countermeasures include: checking the code, Disabling Stack Execution, Safer C library support, using safer Compiler Techniques.
Tools like stackguard, Immunix and vulnerability scanners help securing systems.