Definition
A stack canary, also known as a stack cookie or guard variable, is a security mechanism designed to detect buffer overflow attacks. It involves placing a small, randomly generated value on the program's call stack before a function's local variables. If a buffer overflow occurs and overwrites this canary value, the program can detect the corruption before returning from the function, preventing malicious code execution. This technique is crucial for protecting applications from common memory corruption vulnerabilities that attackers exploit to gain unauthorized access or control. For instance, a web server application might use stack canaries to defend against attacks that attempt to overwrite critical program data. While similar to other memory protection techniques, stack canaries specifically target stack-based overflows. You will encounter stack canaries in discussions related to system hardening and secure coding practices, and they are relevant for certifications like Security+ and CISSP.
