[Forgot Password]
Login  Register Subscribe

30389

 
 

423868

 
 

244625

 
 

909

 
 

193379

 
 

277

Paid content will be excluded from the download.


Download | Alert*
CWE
view XML

Improper Resource Shutdown or Release

ID: 404Date: (C)2012-05-14   (M)2022-10-10
Type: weaknessStatus: DRAFT
Abstraction Type: Base





Description

The program does not release or incorrectly releases a resource before it is made available for re-use.

Extended Description

When a resource is created or allocated, the developer is responsible for properly releasing the resource as well as accounting for all potential paths of expiration or invalidation, such as a set period of time or revocation.

Likelihood of Exploit: Low to Medium

Applicable Platforms
Language Class: All

Time Of Introduction

  • Architecture and Design
  • Implementation

Related Attack Patterns

Common Consequences

ScopeTechnical ImpactNotes
Availability
Other
 
DoS: resource consumption (other)
Varies by context
 
Most unreleased resource issues result in general software reliability problems, but if an attacker can intentionally trigger a resource leak, the attacker might be able to launch a denial of service attack by depleting the resource pool.
 
Confidentiality
 
Read application data
 
When a resource containing sensitive information is not correctly shutdown, it may expose the sensitive data in a subsequent allocation.
 

Detection Methods

NameDescriptionEffectivenessNotes
Automated Dynamic Analysis
 
This weakness can be detected using dynamic tools and techniques that interact with the software using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results.
Resource clean up errors might be detected with a stress-test by calling the software simultaneously from a large number of threads or processes, and look for evidence of any unexpected behavior. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results.
 
Moderate
 
 
Manual Dynamic Analysis
 
Identify error conditions that are not likely to occur during normal usage and trigger them. For example, run the program under low memory conditions, run with insufficient privileges or permissions, interrupt a transaction before it is completed, or disable connectivity to basic network services such as DNS. Monitor the software for any unexpected behavior. If you trigger an unhandled exception or similar error that was discovered and handled by the application's environment, it may still indicate unexpected conditions that were not handled by the application itself.
 
  

Potential Mitigations

PhaseStrategyDescriptionEffectivenessNotes
Requirements
 
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.
 
  
Implementation
 
 It is good practice to be responsible for freeing all resources you allocate and to be consistent with how and where you free memory in a function. If you allocate memory that you intend to free upon completion of the function, you must be sure to free the memory at all exit points for that function including error conditions.
 
  
Implementation
 
 Memory should be allocated/freed using matching functions such as malloc/free, new/delete, and new[]/delete[].
 
  
Implementation
 
 When releasing a complex object or structure, ensure that you properly dispose of all of its member components, not just the object itself.
 
  

Relationships
Overlaps memory leaks, asymmetric resource consumption, malformed input errors.

Related CWETypeViewChain
CWE-404 ChildOf CWE-892 Category CWE-888  

Demonstrative Examples   (Details)

  1. 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. Using the following database connection pattern will ensure that all opened connections are closed. The con.close() call should be the first executable statement in the finally block. (Demonstrative Example Id DX-82)
  2. In this example, the program calls the delete[] function on non-heap memory. (Demonstrative Example Id DX-86)
  3. In this example, the program does not use matching functions such as malloc/free, new/delete, and new[]/delete[] to allocate/deallocate the resource. (Demonstrative Example Id DX-85)
  4. 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. (Demonstrative Example Id DX-84)
  5. The following method never closes the file handle it opens. The Finalize() method for StreamReader eventually calls Close(), but there is no guarantee as to how long it will take before the Finalize() method is invoked. In fact, there is no guarantee that Finalize() will ever be invoked. In a busy environment, this can result in the VM using up all of its available file handles. (Demonstrative Example Id DX-81)
  6. 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. (Demonstrative Example Id DX-83)

Observed Examples

  1. CVE-1999-1127 : Does not shut down named pipe connections if malformed data is sent.
  2. CVE-2001-0830 : Sockets not properly closed when attacker repeatedly connects and disconnects from server.
  3. CVE-2002-1372 : Return values of file/socket operations not checked, allowing resultant consumption of file descriptors.

For more examples, refer to CVE relations in the bottom box.

White Box Definitions
None

Black Box Definitions
None

Taxynomy Mappings

TaxynomyIdNameFit
PLOVER  Improper resource shutdown or release
 
 
7 Pernicious Kingdoms  Unreleased Resource
 
 
OWASP Top Ten 2004 A9
 
Denial of Service
 
CWE_More_Specific
 
CERT C Secure Coding FIO42-C
 
Ensure files are properly closed when they are no longer needed
 
 
CERT Java Secure Coding FIO04-J
 
Release resources when they are no longer needed
 
 
CERT C++ Secure Coding MEM39-CPP
 
Resources allocated by memory allocation functions must be released using the corresponding memory deallocation function
 
 
CERT C++ Secure Coding FIO42-CPP
 
Ensure files are properly closed when they are no longer needed
 
 
CERT C++ Secure Coding CON02-CPP
 
Use lock classes for mutex management
 
 

References:

  1. Michael Howard David LeBlanc John Viega .24 Deadly Sins of Software Security. McGraw-Hill. Section:'"Sin 8: C++ Catastrophes." Page 143'. Published on 2010.
CVE    114
CVE-2016-10363
CVE-2016-8212
CVE-2013-1055
CVE-2013-1054
...

© SecPod Technologies