Logo
-

Byte Open Security

(ByteOS Network)

Log In

Sign Up

ByteOS

Security
Vulnerability Details
Registries
Custom Views
Weaknesses
Attack Patterns
Filters & Tools
CWE-772:Missing Release of Resource after Effective Lifetime
Weakness ID:772
Version:v4.17
Weakness Name:Missing Release of Resource after Effective Lifetime
Vulnerability Mapping:Allowed
Abstraction:Base
Structure:Simple
Status:Draft
Likelihood of Exploit:High
DetailsContent HistoryObserved CVE ExamplesReports
▼Description

The product does not release a resource after its effective lifetime has ended, i.e., after the resource is no longer needed.

▼Extended Description

When a resource is not released after use, it can allow attackers to cause a denial of service by causing the allocation of resources without triggering their release. Frequently-affected resources include memory, CPU, disk space, power or battery, etc.

▼Alternate Terms
▼Relationships
Relevant to the view"Research Concepts - (1000)"
NatureMappingTypeIDName
ChildOfAllowed-with-ReviewC404Improper Resource Shutdown or Release
ParentOfAllowedB1091Use of Object without Invoking Destructor Method
ParentOfAllowedV401Missing Release of Memory after Effective Lifetime
ParentOfAllowedV775Missing Release of File Descriptor or Handle after Effective Lifetime
ParentOfAllowedB911Improper Update of Reference Count
Nature: ChildOf
Mapping: Allowed-with-Review
Type: Class
ID: 404
Name: Improper Resource Shutdown or Release
Nature: ParentOf
Mapping: Allowed
Type: Base
ID: 1091
Name: Use of Object without Invoking Destructor Method
Nature: ParentOf
Mapping: Allowed
Type: Variant
ID: 401
Name: Missing Release of Memory after Effective Lifetime
Nature: ParentOf
Mapping: Allowed
Type: Variant
ID: 775
Name: Missing Release of File Descriptor or Handle after Effective Lifetime
Nature: ParentOf
Mapping: Allowed
Type: Base
ID: 911
Name: Improper Update of Reference Count
▼Memberships
NatureMappingTypeIDName
MemberOfProhibitedC399Resource Management Errors
MemberOfProhibitedC8082010 Top 25 - Weaknesses On the Cusp
MemberOfProhibitedC8672011 Top 25 - Weaknesses On the Cusp
MemberOfProhibitedC882CERT C++ Secure Coding Section 14 - Concurrency (CON)
MemberOfProhibitedV884CWE Cross-section
MemberOfProhibitedC982SFP Secondary Cluster: Failure to Release Resource
MemberOfProhibitedC1129CISQ Quality Measures (2016) - Reliability
MemberOfProhibitedC1131CISQ Quality Measures (2016) - Security
MemberOfProhibitedC1162SEI CERT C Coding Standard - Guidelines 08. Memory Management (MEM)
MemberOfProhibitedC1163SEI CERT C Coding Standard - Guidelines 09. Input Output (FIO)
MemberOfProhibitedV1200Weaknesses in the 2019 CWE Top 25 Most Dangerous Software Errors
MemberOfProhibitedC1416Comprehensive Categorization: Resource Lifecycle Management
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 399
Name: Resource Management Errors
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 808
Name: 2010 Top 25 - Weaknesses On the Cusp
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 867
Name: 2011 Top 25 - Weaknesses On the Cusp
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 882
Name: CERT C++ Secure Coding Section 14 - Concurrency (CON)
Nature: MemberOf
Mapping: Prohibited
Type:View
ID: 884
Name: CWE Cross-section
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 982
Name: SFP Secondary Cluster: Failure to Release Resource
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1129
Name: CISQ Quality Measures (2016) - Reliability
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1131
Name: CISQ Quality Measures (2016) - Security
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1162
Name: SEI CERT C Coding Standard - Guidelines 08. Memory Management (MEM)
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1163
Name: SEI CERT C Coding Standard - Guidelines 09. Input Output (FIO)
Nature: MemberOf
Mapping: Prohibited
Type:View
ID: 1200
Name: Weaknesses in the 2019 CWE Top 25 Most Dangerous Software Errors
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1416
Name: Comprehensive Categorization: Resource Lifecycle Management
▼Tags
NatureMappingTypeIDName
MemberOfProhibitedBSBOSS-274High likelihood of exploit
MemberOfProhibitedBSBOSS-288Language Selection Strategy
MemberOfProhibitedBSBOSS-289Resource Limitation Strategy
MemberOfProhibitedBSBOSS-306Mobile (technology class) Weaknesses
MemberOfProhibitedBSBOSS-333DoS: Resource Consumption (Other) (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-289
Name: Resource Limitation Strategy
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-306
Name: Mobile (technology class) Weaknesses
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-333
Name: DoS: Resource Consumption (Other) (impact)
▼Relevant To View
Relevant to the view"Weaknesses Addressed by the SEI CERT C Coding Standard - (1154)"
NatureMappingTypeIDName
MemberOfProhibitedC1162SEI CERT C Coding Standard - Guidelines 08. Memory Management (MEM)
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 1162
Name: SEI CERT C Coding Standard - Guidelines 08. Memory Management (MEM)
Relevant to the view"Weaknesses Addressed by the SEI CERT C Coding Standard - (1154)"
NatureMappingTypeIDName
MemberOfProhibitedC1163SEI CERT C Coding Standard - Guidelines 09. Input Output (FIO)
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 1163
Name: SEI CERT C Coding Standard - Guidelines 09. Input Output (FIO)
Relevant to the view"Software Development - (699)"
NatureMappingTypeIDName
MemberOfProhibitedC399Resource Management Errors
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 399
Name: Resource Management Errors
Relevant to the view"Software Fault Pattern (SFP) Clusters - (888)"
NatureMappingTypeIDName
MemberOfProhibitedC982SFP Secondary Cluster: Failure to Release Resource
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 982
Name: SFP Secondary Cluster: Failure to Release Resource
▼Background Detail

▼Common Consequences
ScopeLikelihoodImpactNote
AvailabilityN/ADoS: Resource Consumption (Other)

An attacker that can influence the allocation of resources that are not properly released could deplete the available resource pool and prevent all other processes from accessing the same type of resource.

Scope: Availability
Likelihood: N/A
Impact: DoS: Resource Consumption (Other)
Note:

An attacker that can influence the allocation of resources that are not properly released could deplete the available resource pool and prevent all other processes from accessing the same type of resource.

▼Potential Mitigations
Phase:Requirements
Mitigation ID: MIT-3
Strategy: Language Selection
Effectiveness:
Description:

Use a language that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.

For example, languages such as Java, Ruby, and Lisp perform automatic garbage collection that releases memory for objects that have been deallocated.

Note:


Phase:Implementation
Mitigation ID:
Strategy:
Effectiveness:
Description:

It is good practice to be responsible for freeing all resources you allocate and to be consistent with how and where you free resources in a function. If you allocate resources that you intend to free upon completion of the function, you must be sure to free the resources at all exit points for that function including error conditions.

Note:


Phase:Operation, Architecture and Design
Mitigation ID: MIT-47
Strategy: Resource Limitation
Effectiveness:
Description:

Use resource-limiting settings provided by the operating system or environment. For example, when managing system resources in POSIX, setrlimit() can be used to set limits for certain types of resources, and getrlimit() can determine how many resources are available. However, these functions are not available on all operating systems.

When the current levels get close to the maximum that is defined for the application (see CWE-770), then limit the allocation of further resources to privileged users; alternately, begin releasing resources for less-privileged users. While this mitigation may protect the system from attack, it will not necessarily stop attackers from adversely impacting other users.

Ensure that the application performs the appropriate error checks and error handling in case resources become unavailable (CWE-703).

Note:

▼Modes Of Introduction
Phase: Implementation
Note:

N/A

▼Applicable Platforms
Technology
Class: Mobile(Undetermined Prevalence)
▼Demonstrative Examples
Example 1

The following method never closes the new file handle. Given enough time, the Finalize() method for BufferReader should eventually call Close(), but there is no guarantee as to how long this action will take. In fact, there is no guarantee that Finalize() will ever be invoked. In a busy environment, the Operating System could use up all of the available file handles before the Close() function is called.

Language: ( code)
N/A

Language: Java(Bad code)
private void processFile(string fName) { BufferReader fil = new BufferReader(new FileReader(fName)); String line; while ((line = fil.ReadLine()) != null) { processLine(line); } }

Language: ( code)
N/A

The good code example simply adds an explicit call to the Close() function when the system is done using the file. Within a simple example such as this the problem is easy to see and fix. In a real system, the problem may be considerably more obscure.

Language: Java(Good code)
private void processFile(string fName) { BufferReader fil = new BufferReader(new FileReader(fName)); String line; while ((line = fil.ReadLine()) != null) { processLine(line); } fil.Close(); }

Example 2

The following code attempts to open a new connection to a database, process the results returned by the database, and close the allocated SqlConnection object.

Language: ( code)
N/A

Language: C#(Bad code)
SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand(queryString); cmd.Connection = conn; conn.Open(); SqlDataReader rdr = cmd.ExecuteReader(); HarvestResults(rdr); conn.Connection.Close();

Language: ( code)
N/A

The problem with the above code is that if an exception occurs while executing the SQL or processing the results, the SqlConnection object is not closed. If this happens often enough, the database will run out of available cursors and not be able to execute any more SQL queries.

Example 3

This code attempts to open a connection to a database and catches any exceptions that may occur.

Language: ( code)
N/A

Language: Java(Bad code)
try { Connection con = DriverManager.getConnection(some_connection_string); } catch ( Exception e ) { log( e ); }

Language: ( code)
N/A

If an exception occurs after establishing the database connection and before the same connection closes, the pool of database connections may become exhausted. If the number of available connections is exceeded, other users cannot access this resource, effectively denying access to the application.

Example 4

Under normal conditions the following C# code executes a database query, processes the results returned by the database, and closes the allocated SqlConnection object. But if an exception occurs while executing the SQL or processing the results, the SqlConnection object is not closed. If this happens often enough, the database will run out of available cursors and not be able to execute any more SQL queries.

Language: ( code)
N/A

Language: C#(Bad code)
... SqlConnection conn = new SqlConnection(connString); SqlCommand cmd = new SqlCommand(queryString); cmd.Connection = conn; conn.Open(); SqlDataReader rdr = cmd.ExecuteReader(); HarvestResults(rdr); conn.Connection.Close(); ...

Example 5

The following C function does not close the file handle it opens if an error occurs. If the process is long-lived, the process can run out of file handles.

Language: ( code)
N/A

Language: C(Bad code)
int decodeFile(char* fName) { char buf[BUF_SZ]; FILE* f = fopen(fName, "r"); if (!f) { printf("cannot open %s\n", fName); return DECODE_FAIL; } else { while (fgets(buf, BUF_SZ, f)) { if (!checkChecksum(buf)) { return DECODE_FAIL; } else { decodeBlock(buf); } } } fclose(f); return DECODE_SUCCESS; }

▼Observed Examples
ReferenceDescription
CVE-2007-0897
Chain: anti-virus product encounters a malformed file but returns from a function without closing a file descriptor (CWE-775) leading to file descriptor consumption (CWE-400) and failed scans.
CVE-2001-0830
Sockets not properly closed when attacker repeatedly connects and disconnects from server.
CVE-1999-1127
Does not shut down named pipe connections if malformed data is sent.
CVE-2009-2858
Chain: memory leak (CWE-404) leads to resource exhaustion.
CVE-2009-2054
Product allows exhaustion of file descriptors when processing a large number of TCP packets.
CVE-2008-2122
Port scan triggers CPU consumption with processes that attempt to read data from closed sockets.
CVE-2007-4103
Product allows resource exhaustion via a large number of calls that do not complete a 3-way handshake.
CVE-2002-1372
Chain: Return values of file/socket operations are not checked (CWE-252), allowing resultant consumption of file descriptors (CWE-772).
Reference: CVE-2007-0897
Description:
Chain: anti-virus product encounters a malformed file but returns from a function without closing a file descriptor (CWE-775) leading to file descriptor consumption (CWE-400) and failed scans.
Reference: CVE-2001-0830
Description:
Sockets not properly closed when attacker repeatedly connects and disconnects from server.
Reference: CVE-1999-1127
Description:
Does not shut down named pipe connections if malformed data is sent.
Reference: CVE-2009-2858
Description:
Chain: memory leak (CWE-404) leads to resource exhaustion.
Reference: CVE-2009-2054
Description:
Product allows exhaustion of file descriptors when processing a large number of TCP packets.
Reference: CVE-2008-2122
Description:
Port scan triggers CPU consumption with processes that attempt to read data from closed sockets.
Reference: CVE-2007-4103
Description:
Product allows resource exhaustion via a large number of calls that do not complete a 3-way handshake.
Reference: CVE-2002-1372
Description:
Chain: Return values of file/socket operations are not checked (CWE-252), allowing resultant consumption of file descriptors (CWE-772).
▼Affected Resources
    ▼Functional Areas
      ▼Weakness Ordinalities
      OrdinalityDescription
      ▼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
      Maintenance

      "Resource exhaustion" (CWE-400) is currently treated as a weakness, although it is more like a category of weaknesses that all have the same type of consequence. While this entry treats CWE-400 as a parent in view 1000, the relationship is probably more appropriately described as a chain.

      N/A

      Theoretical

      Vulnerability theory is largely about how behaviors and resources interact. "Resource exhaustion" can be regarded as either a consequence or an attack, depending on the perspective. This entry is an attempt to reflect one of the underlying weaknesses that enable these attacks (or consequences) to take place.

      N/A

      ▼Taxonomy Mappings
      Taxonomy NameEntry IDFitEntry Name
      CERT C Secure CodingFIO42-CCWE More AbstractClose files when they are no longer needed
      CERT C Secure CodingMEM31-CCWE More AbstractFree dynamically allocated memory when no longer needed
      OMG ASCSMASCSM-CWE-772N/AN/A
      OMG ASCRMASCRM-CWE-772N/AN/A
      Software Fault PatternsSFP14N/AFailure to Release Resource
      Taxonomy Name: CERT C Secure Coding
      Entry ID: FIO42-C
      Fit: CWE More Abstract
      Entry Name: Close files when they are no longer needed
      Taxonomy Name: CERT C Secure Coding
      Entry ID: MEM31-C
      Fit: CWE More Abstract
      Entry Name: Free dynamically allocated memory when no longer needed
      Taxonomy Name: OMG ASCSM
      Entry ID: ASCSM-CWE-772
      Fit: N/A
      Entry Name: N/A
      Taxonomy Name: OMG ASCRM
      Entry ID: ASCRM-CWE-772
      Fit: N/A
      Entry Name: N/A
      Taxonomy Name: Software Fault Patterns
      Entry ID: SFP14
      Fit: N/A
      Entry Name: Failure to Release Resource
      ▼Related Attack Patterns
      IDName
      CAPEC-469
      HTTP DoS
      ID: CAPEC-469
      Name: HTTP DoS
      ▼References
      Reference ID: REF-961
      Title: Automated Source Code Reliability Measure (ASCRM)
      Author: Object Management Group (OMG)
      Section: ASCRM-CWE-772
      Publication:
      Publisher:
      Edition:
      URL:http://www.omg.org/spec/ASCRM/1.0/
      URL Date:
      Day:N/A
      Month:01
      Year:2016
      Reference ID: REF-962
      Title: Automated Source Code Security Measure (ASCSM)
      Author: Object Management Group (OMG)
      Section: ASCSM-CWE-772
      Publication:
      Publisher:
      Edition:
      URL:http://www.omg.org/spec/ASCSM/1.0/
      URL Date:
      Day:N/A
      Month:01
      Year:2016
      Details not found