Missing Release of File Descriptor or Handle after Effective Lifetime
Weakness ID: 775 (Weakness Variant)Status: Incomplete
+ Description

Description Summary

The software does not release a file descriptor or handle after its effective lifetime has ended, i.e., after the file descriptor/handle is no longer needed.

Extended Description

When a file descriptor or handle is not released after use (typically by explicitly closing it), attackers can cause a denial of service by consuming all available file descriptors/handles, or otherwise preventing other system processes from obtaining their own file descriptors/handles.

+ Time of Introduction
  • Implementation
+ Common Consequences

When allocating resources without limits, an attacker could prevent all other processes from accessing the same type of resource.

+ Likelihood of Exploit

Medium to High

+ Observed Examples
CVE-2007-0897Chain: 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.
+ Potential Mitigations

Phase: Implementation

For system resources, consider using the getrlimit() function included in the sys/resources library in order to determine how many resources are currently allowed to be opened for the process.

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.

(Good Code)
Example Language:
#include <sys/resource.h>
int return_value;
struct rlimit rlp;
return_value = getrlimit(RLIMIT_NOFILE, &rlp);

Phase: Operation

Use resource-limiting settings provided by the operating system or environment. For example, setrlimit() can be used to set limits for certain types of resources. However, this is not available on all operating systems.

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

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfCategoryCategory769File Descriptor Exhaustion
Development Concepts (primary)699
ChildOfWeakness BaseWeakness Base772Missing Release of Resource after Effective Lifetime
Research Concepts (primary)1000
+ Theoretical Notes

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.

+ Content History
Submission DateSubmitterOrganizationSource
2009-05-13Internal CWE Team
Modification DateModifierOrganizationSource
2009-12-28CWE Content TeamMITREInternal
updated Observed Examples