Apex › Security & web

How a stack canary catches the overflow

A linear overflow has to write through everything between the buffer and the return address — so the compiler plants a random secret (the canary, from %fs:0x28) in the way. Reach the return address and you smash the canary; the function epilogue checks it before ret and calls __stack_chk_fail on a mismatch, aborting before your hijacked address is used. Overflow blind and it aborts; leak the canary, write it back, and the check passes. A canary is a check, not a wall.

More in Security & web