Missing Release of Resource after Effective Lifetime

Draft Base
Structure: Simple
Description

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

The product does not release a resource after its effective lifetime has ended, i.e., after the resource is no longer needed.
Common Consequences 1
Scope: Availability

Impact: DoS: Resource Consumption (Other)DoS: Resource Consumption (Memory)DoS: Resource Consumption (CPU)

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. Frequently-affected resources include memory, CPU, disk space, power or battery, etc.

Potential Mitigations 3
Phase: Requirements

Strategy: Language Selection

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.
Phase: Implementation
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.
Phase: OperationArchitecture and Design

Strategy: Resource Limitation

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 Allocation of Resources Without Limits or Throttling), 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 (Improper Check or Handling of Exceptional Conditions).
Demonstrative Examples 5

ID : DX-81

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.

Code Example:

Bad
Java
java
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.

Code Example:

Good
Java
java
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.

Code Example:

Bad
C#
c#
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.

ID : DX-82

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

Code Example:

Bad
Java
java
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.

ID : DX-83

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.

Code Example:

Bad
C#
c#

ID : DX-84

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.

Code Example:

Bad
C
c
Observed Examples 8
CVE-2007-0897Chain: anti-virus product encounters a malformed file but returns from a function without closing a file descriptor (Missing Release of File Descriptor or Handle after Effective Lifetime) leading to file descriptor consumption (Uncontrolled Resource Consumption) and failed scans.
CVE-2001-0830Sockets not properly closed when attacker repeatedly connects and disconnects from server.
CVE-1999-1127Does not shut down named pipe connections if malformed data is sent.
CVE-2009-2858Chain: memory leak (Improper Resource Shutdown or Release) leads to resource exhaustion.
CVE-2009-2054Product allows exhaustion of file descriptors when processing a large number of TCP packets.
CVE-2008-2122Port scan triggers CPU consumption with processes that attempt to read data from closed sockets.
CVE-2007-4103Product allows resource exhaustion via a large number of calls that do not complete a 3-way handshake.
CVE-2002-1372Chain: Return values of file/socket operations are not checked (Unchecked Return Value), allowing resultant consumption of file descriptors (Missing Release of Resource after Effective Lifetime).
References 2
Automated Source Code Reliability Measure (ASCRM)
Object Management Group (OMG)
01-2016
ID: REF-961
Automated Source Code Security Measure (ASCSM)
Object Management Group (OMG)
01-2016
ID: REF-962
Likelihood of Exploit

High

Applicable Platforms
Technologies:
Mobile : Undetermined
Modes of Introduction
Implementation
Taxonomy Mapping
  • CERT C Secure Coding
  • CERT C Secure Coding
  • OMG ASCSM
  • OMG ASCRM
  • Software Fault Patterns
Notes
Maintenance"Resource exhaustion" (Uncontrolled Resource Consumption) 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 Uncontrolled Resource Consumption as a parent in view 1000, the relationship is probably more appropriately described as a chain.
TheoreticalVulnerability 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.