Logo
-

Byte Open Security

(ByteOS Network)

Log In

Sign Up

ByteOS

Security
Vulnerability Details
Registries
Custom Views
Weaknesses
Attack Patterns
Filters & Tools
CWE-123:Write-what-where Condition
Weakness ID:123
Version:v4.17
Weakness Name:Write-what-where Condition
Vulnerability Mapping:Allowed
Abstraction:Base
Structure:Simple
Status:Draft
Likelihood of Exploit:High
DetailsContent HistoryObserved CVE ExamplesReports
▼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.

▼Extended Description

▼Alternate Terms
▼Relationships
Relevant to the view"Research Concepts - (1000)"
NatureMappingTypeIDName
ChildOfAllowedB787Out-of-bounds Write
ParentOfAllowed-with-ReviewB120Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
ParentOfAllowedB134Use of Externally-Controlled Format String
ParentOfAllowedB364Signal Handler Race Condition
ParentOfAllowedV415Double Free
ParentOfAllowedV416Use After Free
ParentOfAllowedV479Signal Handler Use of a Non-reentrant Function
ParentOfAllowedV590Free of Memory not on the Heap
Nature: ChildOf
Mapping: Allowed
Type: Base
ID: 787
Name: Out-of-bounds Write
Nature: ParentOf
Mapping: Allowed-with-Review
Type: Base
ID: 120
Name: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
Nature: ParentOf
Mapping: Allowed
Type: Base
ID: 134
Name: Use of Externally-Controlled Format String
Nature: ParentOf
Mapping: Allowed
Type: Base
ID: 364
Name: Signal Handler Race Condition
Nature: ParentOf
Mapping: Allowed
Type: Variant
ID: 415
Name: Double Free
Nature: ParentOf
Mapping: Allowed
Type: Variant
ID: 416
Name: Use After Free
Nature: ParentOf
Mapping: Allowed
Type: Variant
ID: 479
Name: Signal Handler Use of a Non-reentrant Function
Nature: ParentOf
Mapping: Allowed
Type: Variant
ID: 590
Name: Free of Memory not on the Heap
▼Memberships
NatureMappingTypeIDName
MemberOfProhibitedC970SFP Secondary Cluster: Faulty Buffer Access
MemberOfProhibitedC1160SEI CERT C Coding Standard - Guidelines 06. Arrays (ARR)
MemberOfProhibitedC1161SEI CERT C Coding Standard - Guidelines 07. Characters and Strings (STR)
MemberOfProhibitedC1399Comprehensive Categorization: Memory Safety
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 970
Name: SFP Secondary Cluster: Faulty Buffer Access
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1160
Name: SEI CERT C Coding Standard - Guidelines 06. Arrays (ARR)
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1161
Name: SEI CERT C Coding Standard - Guidelines 07. Characters and Strings (STR)
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1399
Name: Comprehensive Categorization: Memory Safety
▼Tags
NatureMappingTypeIDName
MemberOfProhibitedBSBOSS-274High likelihood of exploit
MemberOfProhibitedBSBOSS-288Language Selection Strategy
MemberOfProhibitedBSBOSS-311Execute Unauthorized Code or Commands (impact)
MemberOfProhibitedBSBOSS-312Other (impact)
MemberOfProhibitedBSBOSS-316Bypass Protection Mechanism (impact)
MemberOfProhibitedBSBOSS-324DoS: Crash, Exit, or Restart (impact)
MemberOfProhibitedBSBOSS-331Modify Memory (impact)
MemberOfProhibitedBSBOSS-332Gain Privileges or Assume Identity (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-274
Name: High likelihood of exploit
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-288
Name: Language Selection Strategy
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-311
Name: Execute Unauthorized Code or Commands (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-312
Name: Other (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-316
Name: Bypass Protection Mechanism (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-324
Name: DoS: Crash, Exit, or Restart (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-331
Name: Modify Memory (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-332
Name: Gain Privileges or Assume Identity (impact)
▼Relevant To View
Relevant to the view"Weaknesses Addressed by the SEI CERT C Coding Standard - (1154)"
NatureMappingTypeIDName
MemberOfProhibitedC1160SEI CERT C Coding Standard - Guidelines 06. Arrays (ARR)
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 1160
Name: SEI CERT C Coding Standard - Guidelines 06. Arrays (ARR)
Relevant to the view"Weaknesses Addressed by the SEI CERT C Coding Standard - (1154)"
NatureMappingTypeIDName
MemberOfProhibitedC1161SEI CERT C Coding Standard - Guidelines 07. Characters and Strings (STR)
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 1161
Name: SEI CERT C Coding Standard - Guidelines 07. Characters and Strings (STR)
Relevant to the view"Software Fault Pattern (SFP) Clusters - (888)"
NatureMappingTypeIDName
MemberOfProhibitedC970SFP Secondary Cluster: Faulty Buffer Access
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 970
Name: SFP Secondary Cluster: Faulty Buffer Access
▼Background Detail

▼Common Consequences
ScopeLikelihoodImpactNote
IntegrityConfidentialityAvailabilityAccess ControlN/AModify MemoryExecute Unauthorized Code or CommandsGain Privileges or Assume IdentityDoS: Crash, Exit, or RestartBypass Protection Mechanism

Clearly, write-what-where conditions can be used to write data to areas of memory outside the scope of a policy. Also, they almost invariably can be used to execute arbitrary code, which is usually outside the scope of a program's implicit security policy. If the attacker can overwrite a pointer's worth of memory (usually 32 or 64 bits), they can redirect a function pointer to their own malicious code. Even when the attacker can only modify a single byte arbitrary code execution can be possible. Sometimes this is because the same problem can be exploited repeatedly to the same effect. Other times it is because the attacker can overwrite security-critical application-specific data -- such as a flag indicating whether the user is an administrator.

IntegrityAvailabilityN/ADoS: Crash, Exit, or RestartModify Memory

Many memory accesses can lead to program termination, such as when writing to addresses that are invalid for the current process.

Access ControlOtherN/ABypass Protection MechanismOther

When the consequence is arbitrary code execution, this can often be used to subvert any other security service.

Scope: Integrity, Confidentiality, Availability, Access Control
Likelihood: N/A
Impact: Modify Memory, Execute Unauthorized Code or Commands, Gain Privileges or Assume Identity, DoS: Crash, Exit, or Restart, Bypass Protection Mechanism
Note:

Clearly, write-what-where conditions can be used to write data to areas of memory outside the scope of a policy. Also, they almost invariably can be used to execute arbitrary code, which is usually outside the scope of a program's implicit security policy. If the attacker can overwrite a pointer's worth of memory (usually 32 or 64 bits), they can redirect a function pointer to their own malicious code. Even when the attacker can only modify a single byte arbitrary code execution can be possible. Sometimes this is because the same problem can be exploited repeatedly to the same effect. Other times it is because the attacker can overwrite security-critical application-specific data -- such as a flag indicating whether the user is an administrator.

Scope: Integrity, Availability
Likelihood: N/A
Impact: DoS: Crash, Exit, or Restart, Modify Memory
Note:

Many memory accesses can lead to program termination, such as when writing to addresses that are invalid for the current process.

Scope: Access Control, Other
Likelihood: N/A
Impact: Bypass Protection Mechanism, Other
Note:

When the consequence is arbitrary code execution, this can often be used to subvert any other security service.

▼Potential Mitigations
Phase:Architecture and Design
Mitigation ID:
Strategy: Language Selection
Effectiveness:
Description:

Use a language that provides appropriate memory abstractions.

Note:


Phase:Operation
Mitigation ID:
Strategy:
Effectiveness:
Description:

Use OS-level preventative functionality integrated after the fact. Not a complete solution.

Note:

▼Modes Of Introduction
Phase: Implementation
Note:

N/A

▼Applicable Platforms
Languages
Class: C(Undetermined Prevalence)
Class: C++(Undetermined Prevalence)
▼Demonstrative Examples
Example 1

The classic example of a write-what-where condition occurs when the accounting information for memory allocations is overwritten in a particular fashion. Here is an example of potentially vulnerable code:

Language: ( code)
N/A

Language: C(Bad code)
#define BUFSIZE 256 int main(int argc, char **argv) { char *buf1 = (char *) malloc(BUFSIZE); char *buf2 = (char *) malloc(BUFSIZE); strcpy(buf1, argv[1]); free(buf2); }

Language: ( code)
N/A

Vulnerability in this case is dependent on memory layout. The call to strcpy() can be used to write past the end of buf1, and, with a typical layout, can overwrite the accounting information that the system keeps for buf2 when it is allocated. Note that if the allocation header for buf2 can be overwritten, buf2 itself can be overwritten as well.

Language: ( code)
N/A

The allocation header will generally keep a linked list of memory "chunks". Particularly, there may be a "previous" chunk and a "next" chunk. Here, the previous chunk for buf2 will probably be buf1, and the next chunk may be null. When the free() occurs, most memory allocators will rewrite the linked list using data from buf2. Particularly, the "next" chunk for buf1 will be updated and the "previous" chunk for any subsequent chunk will be updated. The attacker can insert a memory address for the "next" chunk and a value to write into that memory address for the "previous" chunk.

Language: ( code)
N/A

This could be used to overwrite a function pointer that gets dereferenced later, replacing it with a memory address that the attacker has legitimate access to, where they have placed malicious code, resulting in arbitrary code execution.

▼Observed Examples
ReferenceDescription
CVE-2022-21668
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 (CWE-190).
CVE-2022-0545
Chain: 3D renderer has an integer overflow (CWE-190) leading to write-what-where condition (CWE-123) using a crafted image.
Reference: CVE-2022-21668
Description:
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 (CWE-190).
Reference: CVE-2022-0545
Description:
Chain: 3D renderer has an integer overflow (CWE-190) leading to write-what-where condition (CWE-123) using a crafted image.
▼Affected Resources
    ▼Functional Areas
      ▼Weakness Ordinalities
      OrdinalityDescription
      Resultant
      N/A
      Ordinality: Resultant
      Description:
      N/A
      ▼Detection Methods
      ▼Vulnerability Mapping Notes
      Usage:Allowed
      Reason:Acceptable-Use
      Rationale:

      This CWE entry is at the Base 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.

      Suggestions:
      ▼Notes
      ▼Taxonomy Mappings
      Taxonomy NameEntry IDFitEntry Name
      CLASPN/AN/AWrite-what-where condition
      CERT C Secure CodingARR30-CImpreciseDo not form or use out-of-bounds pointers or array subscripts
      CERT C Secure CodingARR38-CImpreciseGuarantee that library functions do not form invalid pointers
      CERT C Secure CodingSTR31-CImpreciseGuarantee that storage for strings has sufficient space for character data and the null terminator
      CERT C Secure CodingSTR32-CImpreciseDo not pass a non-null-terminated character sequence to a library function that expects a string
      Software Fault PatternsSFP8N/AFaulty Buffer Access
      Taxonomy Name: CLASP
      Entry ID: N/A
      Fit: N/A
      Entry Name: Write-what-where condition
      Taxonomy Name: CERT C Secure Coding
      Entry ID: ARR30-C
      Fit: Imprecise
      Entry Name: Do not form or use out-of-bounds pointers or array subscripts
      Taxonomy Name: CERT C Secure Coding
      Entry ID: ARR38-C
      Fit: Imprecise
      Entry Name: Guarantee that library functions do not form invalid pointers
      Taxonomy Name: CERT C Secure Coding
      Entry ID: STR31-C
      Fit: Imprecise
      Entry Name: Guarantee that storage for strings has sufficient space for character data and the null terminator
      Taxonomy Name: CERT C Secure Coding
      Entry ID: STR32-C
      Fit: Imprecise
      Entry Name: Do not pass a non-null-terminated character sequence to a library function that expects a string
      Taxonomy Name: Software Fault Patterns
      Entry ID: SFP8
      Fit: N/A
      Entry Name: Faulty Buffer Access
      ▼Related Attack Patterns
      IDName
      ▼References
      Reference ID: REF-44
      Title: 24 Deadly Sins of Software Security
      Author: Michael Howard, David LeBlanc, John Viega
      Section: "Sin 5: Buffer Overruns." Page 89
      Publication:
      McGraw-Hill
      Publisher:
      Edition:
      URL:
      URL Date:
      Day:N/A
      Month:N/A
      Year:2010
      Reference ID: REF-18
      Title: The CLASP Application Security Process
      Author: Secure Software, Inc.
      Section:
      Publication:
      Publisher:
      Edition:
      URL:https://cwe.mitre.org/documents/sources/TheCLASPApplicationSecurityProcess.pdf
      URL Date:2024-11-17
      Day:N/A
      Month:N/A
      Year:2005
      Details not found