CWE-121: Stack-based Buffer Overflow
Also known as: Stack Overflow, Stack Buffer Overflow
The product writes past the end of a buffer that was allocated on the stack.
Last updated
Also known as: Stack Overflow, Stack Buffer Overflow
The product writes past the end of a buffer that was allocated on the stack.
Last updated
CWE-121 (Stack-based Buffer Overflow) is a variant-level software weakness catalogued by MITRE in the Common Weakness Enumeration (CWE). It describes a recurring type of mistake that can lead to exploitable security vulnerabilities.
There are generally several security-critical data on an execution stack that can lead to arbitrary code execution. The most prominent is the stored return address, the memory address at which execution should continue once the current function is finished executing. The attacker can overwrite this value with some memory address to which the attacker also has write access, into which they place arbitrary code to be run with the full privileges of the vulnerable program. Alternately, the attacker can supply the address of an important call, for instance the POSIX system() call, leaving arguments to the call on the stack. This is often called a return into libc exploit, since the attacker generally forces the program to jump at return time into an interesting routine in the C standard library (libc). Other important data commonly on the stack include the stack pointer and frame pointer, two values that indicate offsets for computing memory addresses. Modifying those values can often be leveraged into a "write-what-where" condition.
4,193 recorded CVEs are caused by CWE-121 (Stack-based Buffer Overflow), including 20 in CISA's KEV (Known Exploited Vulnerabilities) catalog. KEVs are shown first. 1,543 new CWE-121 CVEs have been recorded so far in 2026 (883 in 2025).
Cisco Small Business RV Series Routers Vulnerabilities
Cisco Small Business RV Series Routers Vulnerabilities
Cisco Small Business RV Series Routers Vulnerabilities
Cisco Small Business RV Series Routers Vulnerabilities
Cisco Small Business RV Series Routers Vulnerabilities
Ivanti Connect Secure, Policy Secure, and ZTA Gateways Stack-Based Buffer Overflow Vulnerability
Ivanti Connect Secure, Policy Secure, and ZTA Gateways Stack-Based Buffer Overflow Vulnerability
BigIP APM Vulnerability
Fortinet Multiple Products Stack-Based Buffer Overflow Vulnerability
Qualitia Active! Mail Stack-Based Buffer Overflow Vulnerability
SonicWall SMA 100 Appliances Stack-Based Buffer Overflow Vulnerability
Adobe Flash Player Stack-Based Buffer Overflow Vulnerability
Showing 12 of 4,193 recorded CWE-121 CVEs. Get an alert for each new one, with AI-written analysis and fixes.
Monitor these CVEsWhat can happen when CWE-121 is exploited.
Modify Memory, DoS: Crash, Exit, or Restart, DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory)
Affects: Availability
Buffer overflows generally lead to crashes. Other attacks leading to lack of availability are possible, including putting the program into an infinite loop.
Modify Memory, Execute Unauthorized Code or Commands, Bypass Protection Mechanism
Affects: Integrity, Confidentiality, Availability, Access Control
Buffer overflows often can be used to execute arbitrary code, which is usually outside the scope of a program's implicit security policy.
Modify Memory, Execute Unauthorized Code or Commands, Bypass Protection Mechanism, Other
Affects: Integrity, Confidentiality, Availability, Access Control, Other
When the consequence is arbitrary code execution, this can often be used to subvert any other security service.
Typically introduced during these phases of the software lifecycle.
Languages
Practical mitigations for CWE-121, grouped by where in the lifecycle they apply.
Use automatic buffer overflow detection mechanisms that are offered by certain compilers or compiler extensions. Examples include: the Microsoft Visual Studio /GS flag, Fedora/Red Hat FORTIFY_SOURCE GCC flag, StackGuard, and ProPolice, which provide various mechanisms including canary-based detection and range/index checking.
D3-SFCV (Stack Frame Canary Validation) from D3FEND [11] discusses canary-based detection in detail.
Effectiveness: Defense in Depth — This is not necessarily a complete solution, since these mechanisms only detect certain types of overflows. In addition, the result is still a denial of service, since the typical response is to exit the application.
Use an abstraction library to abstract away risky APIs. Not a complete solution.
Implement and perform bounds checking on input.
Do not use dangerous functions such as gets. Use safer, equivalent functions which check for boundary errors.
Run or compile the software using features or extensions that randomly arrange the positions of a program's executable and libraries in memory. Because this makes the addresses unpredictable, it can prevent an attacker from reliably jumping to exploitable code.
Examples include Address Space Layout Randomization (ASLR) [6] [7] and Position-Independent Executables (PIE) [8]. Imported modules may be similarly realigned if their default memory addresses conflict with other modules, in a process known as "rebasing" (for Windows) and "prelinking" (for Linux) [9] using randomly generated addresses. ASLR for libraries cannot be used in conjunction with prelink since it would require relocating the libraries at run-time, defeating the whole purpose of prelinking.
For more information on these techniques see D3-SAOR (Segment Address Offset Randomization) from D3FEND [12].
Effectiveness: Defense in Depth — These techniques do not provide a complete solution. For instance, exploits frequently use a bug that discloses memory addresses in order to maximize reliability of code execution [13]. It has also been shown that a side-channel attack can bypass ASLR [10].
Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.
Effectiveness: High
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
Effectiveness: High
Use tools that are integrated during compilation to insert runtime error-checking mechanisms related to memory safety errors, such as AddressSanitizer (ASan) for C/C++ [15].
Effectiveness: Moderate
MITRE examples of the weakness in code.
While buffer overflow examples can be rather complex, it is possible to have very simple, yet still exploitable, stack-based buffer overflows:
Vulnerable example
#define BUFSIZE 256
int main(int argc, char **argv) {
char buf[BUFSIZE];
strcpy(buf, argv[1]);
}The buffer size is fixed, but there is no guarantee the string in argv[1] will not exceed this size and cause an overflow.
This example takes an IP address from a user, verifies that it is well formed and then looks up the hostname and copies it into a buffer.
Vulnerable example
void host_lookup(char *user_supplied_addr){
struct hostent *hp;
in_addr_t *addr;
char hostname[64];
in_addr_t inet_addr(const char *cp);
/*routine that ensures user_supplied_addr is in the right format for conversion */
validate_addr_form(user_supplied_addr);
addr = inet_addr(user_supplied_addr);
hp = gethostbyaddr( addr, sizeof(struct in_addr), AF_INET);
strcpy(hostname, hp->h_name);
}Real CVEs that MITRE cites as examples of this weakness.
Common questions about CWE-121.
Weakness data is sourced from the MITRE CWE catalog (v4.21). CVE associations are aggregated and kept current by RadicalNotion.AI.
Get an alert when a new CWE-121 CVE affects your products, with AI-written analysis and remediation steps.