CWE-672: Operation on a Resource after Expiration or Release
Official CWE-672 CWE context with Glexia analysis, remediation guidance, related CVEs, and ATT&CK context.
Glexia's Take
CWE-672: Operation on a Resource after Expiration or Release
Operation on a Resource after Expiration or Release represents a recurring weakness pattern that can create exploitable paths when design, validation, or implementation controls are missing.
Executive Impact
- Integrity,Confidentiality: Modify Application Data,Read Application Data: If a released resource is subsequently reused or reallocated, then an attempt to use the original resource might allow access to sensitive data that is associated with a different user or entity.
- Other,Availability: Other,DoS: Crash, Exit, or Restart: When a resource is released it might not be in an expected state, later attempts to access the resource may lead to resultant errors that may lead to a crash.
Developer Pattern
CWE-672 is the kind of defect developers can usually prevent with explicit validation, safer framework defaults, and tests that exercise hostile input or unsafe state transitions.
Confidence
high confidence from CWE-672, 4.20.
Official CWE Definition
CWE-672: Operation on a Resource after Expiration or Release
The product uses, accesses, or otherwise operates on a resource after that resource has been expired, released, or revoked.
Developer And Remediation Guidance
How teams prevent and detect this weakness
Causes
- The following code shows a simple example of a use after free error: When an error occurs, the pointer is immediately freed. However, this pointer is later incorrectly used in the logError function.
- The following code shows a simple example of a double free error: Double free vulnerabilities have two common (and sometimes overlapping) causes:,[object Object],Although some double free vulnerabilities are not much more complicated than the previous example, most are spread out across hundreds of lines of code or even different files. Programmers seem particularly susceptible to freeing global variables more than once.
- In the following C/C++ example the method processMessage is used to process a message received in the input array of char arrays. The input message array contains two char arrays: the first is the length of the message and the second is the body of the message. The length of the message is retrieved and used to allocate enough memory for a local char array, messageBody, to be created for the message body. The messageBody is processed in the method processMessageBody that will return an error if an error occurs while processing. If an error occurs then the return result variable is set to indicate an error and the messageBody char array memory is released using the method free and an error message is sent to the logError method. However, the call to the method logError includes the messageBody after the memory for messageBody has been released using the free method. This can cause unexpected results and may lead to system crashes. A variable should never be used after its memory resources have been released.
Remediation
- Use safe APIs
- Centralize the control
- Add regression tests
- Review logs and telemetry for attempted abuse
Detection
- Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
Mappings
Related CVEs, CWEs, and ATT&CK context
Related CWEs
- CWE-1341: Multiple Releases of Same Resource or Handle
- CWE-298: Improper Validation of Certificate Expiration
- CWE-324: Use of a Key Past its Expiration Date
- CWE-415: Double Free
- CWE-415: Double Free
- CWE-415: Double Free
- CWE-416: Use After Free
- CWE-416: Use After Free
- CWE-416: Use After Free
- CWE-562: Return of Stack Variable Address
- CWE-613: Insufficient Session Expiration
- CWE-613: Insufficient Session Expiration
ATT&CK Relevance
ATT&CK relevance is shown only when reviewed or responsibly inferred.