Background Details
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.
Modes Of Introduction
Implementation
Applicable Platforms
Language
Name: C (Undetermined)
Name: C++ (Undetermined)
Common Consequences
Scope |
Impact |
Likelihood |
Availability | Modify Memory, DoS: Crash, Exit, or Restart, DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory)
Note: Buffer overflows generally lead to crashes. Other attacks leading to lack of availability are possible, including putting the program into an infinite loop. | |
Integrity Confidentiality Availability Access Control | Modify Memory, Execute Unauthorized Code or Commands, Bypass Protection Mechanism
Note: Buffer overflows often can be used to execute arbitrary code, which is usually outside the scope of a program's implicit security policy. | |
Integrity Confidentiality Availability Access Control Other | Modify Memory, Execute Unauthorized Code or Commands, Bypass Protection Mechanism, Other
Note: When the consequence is arbitrary code execution, this can often be used to subvert any other security service. | |
Observed Examples
Reference |
Description |
CVE-2021-35395 | Stack-based buffer overflows in SFK for wifi chipset used for IoT/embedded devices, as exploited in the wild per CISA KEV. |
Potential Mitigations
Phases : Operation // Build and Compilation
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 [REF-1334] discusses canary-based detection in detail.
Phases : Architecture and Design
Use an abstraction library to abstract away risky APIs. Not a complete solution.
Phases : Implementation
Implement and perform bounds checking on input.
Phases : Implementation
Do not use dangerous functions such as gets. Use safer, equivalent functions which check for boundary errors.
Phases : Operation // Build and Compilation
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) [REF-58] [REF-60] and Position-Independent Executables (PIE) [REF-64]. 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) [REF-1332] 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 [REF-1335].
Detection Methods
Fuzzing
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
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
Vulnerability Mapping Notes
Rationale : This CWE entry is at the Variant level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.
Comments : Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.
Notes
Stack-based buffer overflows can instantiate in return address overwrites, stack pointer overwrites or frame pointer overwrites. They can also be considered function pointer overwrites, array indexer overwrites or write-what-where condition, etc.
References
REF-1029
Smashing The Stack For Fun And Profit
Aleph One.
http://phrack.org/issues/49/14.html REF-7
Writing Secure Code
Michael Howard, David LeBlanc.
https://www.microsoftpressstore.com/store/writing-secure-code-9780735617223 REF-44
24 Deadly Sins of Software Security
Michael Howard, David LeBlanc, John Viega.
REF-62
The Art of Software Security Assessment
Mark Dowd, John McDonald, Justin Schuh.
REF-62
The Art of Software Security Assessment
Mark Dowd, John McDonald, Justin Schuh.
REF-18
The CLASP Application Security Process
Secure Software, Inc..
https://cwe.mitre.org/documents/sources/TheCLASPApplicationSecurityProcess.pdf REF-58
Address Space Layout Randomization in Windows Vista
Michael Howard.
https://learn.microsoft.com/en-us/archive/blogs/michael_howard/address-space-layout-randomization-in-windows-vista REF-60
PaX
https://en.wikipedia.org/wiki/Executable_space_protection#PaX REF-64
Position Independent Executables (PIE)
Grant Murphy.
https://www.redhat.com/en/blog/position-independent-executables-pie REF-1332
Prelink and address space randomization
John Richard Moser.
https://lwn.net/Articles/190139/ REF-1333
Jump Over ASLR: Attacking Branch Predictors to Bypass ASLR
Dmitry Evtyushkin, Dmitry Ponomarev, Nael Abu-Ghazaleh.
http://www.cs.ucr.edu/~nael/pubs/micro16.pdf REF-1334
Stack Frame Canary Validation (D3-SFCV)
D3FEND.
https://d3fend.mitre.org/technique/d3f:StackFrameCanaryValidation/ REF-1335
Segment Address Offset Randomization (D3-SAOR)
D3FEND.
https://d3fend.mitre.org/technique/d3f:SegmentAddressOffsetRandomization/ REF-1337
Bypassing Browser Memory Protections: Setting back browser security by 10 years
Alexander Sotirov and Mark Dowd.
https://www.blackhat.com/presentations/bh-usa-08/Sotirov_Dowd/bh08-sotirov-dowd.pdf
Submission
Name |
Organization |
Date |
Date Release |
Version |
CLASP |
|
2006-07-19 +00:00 |
2006-07-19 +00:00 |
Draft 3 |
Modifications
Name |
Organization |
Date |
Comment |
Eric Dalci |
Cigital |
2008-07-01 +00:00 |
updated Potential_Mitigations, Time_of_Introduction |
|
KDM Analytics |
2008-08-01 +00:00 |
added/updated white box definitions |
CWE Content Team |
MITRE |
2008-09-08 +00:00 |
updated Alternate_Terms, Applicable_Platforms, Background_Details, Common_Consequences, Relationships, Other_Notes, Taxonomy_Mappings, Weakness_Ordinalities |
CWE Content Team |
MITRE |
2009-01-12 +00:00 |
updated Common_Consequences, Relationships |
KDM Analytics |
|
2009-07-17 +00:00 |
Improved the White_Box_Definition |
CWE Content Team |
MITRE |
2009-07-27 +00:00 |
updated Potential_Mitigations, White_Box_Definitions |
CWE Content Team |
MITRE |
2009-10-29 +00:00 |
updated Relationships |
CWE Content Team |
MITRE |
2010-02-16 +00:00 |
updated References |
CWE Content Team |
MITRE |
2011-06-01 +00:00 |
updated Common_Consequences |
CWE Content Team |
MITRE |
2012-05-11 +00:00 |
updated Demonstrative_Examples, References, Relationships |
CWE Content Team |
MITRE |
2012-10-30 +00:00 |
updated Demonstrative_Examples, Potential_Mitigations |
CWE Content Team |
MITRE |
2014-07-30 +00:00 |
updated Relationships, Taxonomy_Mappings |
CWE Content Team |
MITRE |
2017-11-08 +00:00 |
updated Background_Details, Causal_Nature, Likelihood_of_Exploit, References, Relationships, Taxonomy_Mappings, White_Box_Definitions |
CWE Content Team |
MITRE |
2018-03-27 +00:00 |
updated References |
CWE Content Team |
MITRE |
2019-01-03 +00:00 |
updated Relationships |
CWE Content Team |
MITRE |
2019-09-19 +00:00 |
updated References |
CWE Content Team |
MITRE |
2020-02-24 +00:00 |
updated Relationships |
CWE Content Team |
MITRE |
2020-06-25 +00:00 |
updated Common_Consequences |
CWE Content Team |
MITRE |
2021-03-15 +00:00 |
updated Demonstrative_Examples, References |
CWE Content Team |
MITRE |
2021-07-20 +00:00 |
updated Demonstrative_Examples |
CWE Content Team |
MITRE |
2022-06-28 +00:00 |
updated Observed_Examples |
CWE Content Team |
MITRE |
2023-04-27 +00:00 |
updated Detection_Factors, Potential_Mitigations, References, Relationships, Time_of_Introduction |
CWE Content Team |
MITRE |
2023-06-29 +00:00 |
updated Mapping_Notes, Relationships |