Description
Any condition where the attacker has the ability to write an arbitrary value to an arbitrary location, often as the result of a buffer overflow.
Potential Impact
Integrity, Confidentiality, Availability, Access Control
Modify Memory, Execute Unauthorized Code or Commands, Gain Privileges or Assume Identity, DoS: Crash, Exit, or Restart, Bypass Protection Mechanism
Integrity, Availability
DoS: Crash, Exit, or Restart, Modify Memory
Access Control, Other
Bypass Protection Mechanism, Other
Demonstrative Examples
#define BUFSIZE 256int main(int argc, char **argv) {char *buf1 = (char *) malloc(BUFSIZE);char *buf2 = (char *) malloc(BUFSIZE);strcpy(buf1, argv[1]);free(buf2);}Mitigations & Prevention
Use a language that provides appropriate memory abstractions.
Use OS-level preventative functionality integrated after the fact. Not a complete solution.
Detection Methods
- Automated Static Analysis 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 sea
- Automated Dynamic Analysis Moderate — 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++ [REF-1518].
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| CVE-2019-19911 | Chain: Python library does not limit the resources used to process images that specify a very large number of bands (CWE-1284), leading to excessive memory consumption (CWE-789) or an integer overflow |
| CVE-2022-0545 | Chain: 3D renderer has an integer overflow (CWE-190) leading to write-what-where condition (CWE-123) using a crafted image. |
Related Weaknesses
Taxonomy Mappings
- CLASP: — Write-what-where condition
- CERT C Secure Coding: ARR30-C — Do not form or use out-of-bounds pointers or array subscripts
- CERT C Secure Coding: ARR38-C — Guarantee that library functions do not form invalid pointers
- CERT C Secure Coding: STR31-C — Guarantee that storage for strings has sufficient space for character data and the null terminator
- CERT C Secure Coding: STR32-C — Do not pass a non-null-terminated character sequence to a library function that expects a string
- Software Fault Patterns: SFP8 — Faulty Buffer Access
Frequently Asked Questions
What is CWE-123?
CWE-123 (Write-what-where Condition) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. Any condition where the attacker has the ability to write an arbitrary value to an arbitrary location, often as the result of a buffer overflow.
How can CWE-123 be exploited?
Attackers can exploit CWE-123 (Write-what-where Condition) to modify memory, execute unauthorized code or commands, gain privileges or assume identity, dos: crash, exit, or restart, bypass protection mechanism. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-123?
Key mitigations include: Use a language that provides appropriate memory abstractions.
What is the severity of CWE-123?
CWE-123 is classified as a Base-level weakness (Medium abstraction). It has been observed in 2 real-world CVEs.