Stack canaries are random, secret values placed on the stack between local variables and the return address. If this canary value is modified before a function returns, it signals a buffer overflow, causing the program to terminate and preventing malicious code execution.