How GCC's DEP/NX Flag Controls Stack Execution to Mitigate Buffer Overflows
A DEV Community tutorial explores how GCC's execstack and noexecstack linker flags control whether the stack memory segment is marked executable or non-executable on x86_64 Linux systems. The article uses a deliberately vulnerable C server program that copies a 256-byte request buffer into a 64-byte stack buffer via strcpy, creating a classic stack-based buffer overflow. The author compiles the program twice — once with -z execstack and once with -z noexecstack — then disassembles both binaries using objdump and inspects memory segment permissions with readelf. This comparison illustrates how the NX (No-Execute) or DEP (Data Execution Prevention) protection works at the binary level to prevent injected shellcode on the stack from being executed. The piece is part of a broader series examining what GCC actually does when transforming C source code into a compiled binary.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in