What it is: Multiple Unlocks of a Critical Resource (CWE-765) is a vulnerability that occurs when a program unlocks a critical resource more times than intended, leading to unexpected system states.
Why it matters: This can result in DoS conditions and memory corruption, affecting the availability and integrity of systems.
How to fix it: Ensure proper unlocking occurs regardless of control flow paths and exceptions.
TL;DR: Multiple Unlocks of a Critical Resource (CWE-765) is a vulnerability where a program unlocks critical resources more times than intended, leading to unexpected system states. Proper locking mechanisms must be implemented to prevent this issue.
| Field | Value |
|---|---|
| CWE ID | CWE-765 |
| OWASP Category | Not directly mapped |
| CAPEC | None known |
| Typical Severity | High |
| Affected Technologies | any language/framework that manages resources |
| Detection Difficulty | Moderate |
| Last Updated | 2026-07-29 |
What is Multiple Unlocks of a Critical Resource?
Multiple Unlocks of a Critical Resource (CWE-765) is a type of vulnerability where a program unlocks critical resources more times than intended, leading to unexpected system states. As defined by the MITRE Corporation under CWE-765 and not classified by the OWASP Foundation under any specific category.
Quick Summary
Multiple Unlocks of a Critical Resource can lead to DoS conditions, memory corruption, and unexpected behavior affecting both availability and integrity. It is critical to ensure proper unlocking mechanisms are in place regardless of control flow paths or exceptions. Jump to: Overview · How it Works · Business Impact · Attack Scenario · Detection · Fixing · Framework Fixes · Ask AI · Best Practices · FAQ
Jump to: Quick Summary · Multiple Unlocks of a Critical Resource Overview · How Multiple Unlocks of a Critical Resource Works · Business Impact of Multiple Unlocks of a Critical Resource · Multiple Unlocks of a Critical Resource Attack Scenario · How to Detect Multiple Unlocks of a Critical Resource · How to Fix Multiple Unlocks of a Critical Resource · Framework-Specific Fixes for Multiple Unlocks of a Critical Resource · How to Ask AI to Check Your Code for Multiple Unlocks of a Critical Resource · Multiple Unlocks of a Critical Resource Best Practices Checklist · Multiple Unlocks of a Critical Resource FAQ · Vulnerabilities Related to Multiple Unlocks of a Critical Resource · References · Scan Your Own Site
Multiple Unlocks of a Critical Resource Overview
What: A program unlocks critical resources more times than intended, leading to unexpected system states.
Why it matters: This can result in DoS conditions and memory corruption, affecting the availability and integrity of systems.
Where it occurs: In any language/framework that manages resources.
Who is affected: Developers who manage resource locks across different control paths.
Who is NOT affected: Systems already using robust locking mechanisms with proper unlocking procedures.
How Multiple Unlocks of a Critical Resource Works
Root Cause
The root cause lies in the improper management of critical resource locks, where a program unlocks resources more times than intended. This can occur due to complex control flow paths or exception handling that fails to ensure consistent lock management.
Attack Flow
- The attacker identifies a function that acquires and releases locks on critical resources.
- They exploit conditional logic or exceptions within the code to cause multiple unlocks, leading to an unexpected state in the system.
- This results in DoS conditions, memory corruption, or other unexpected behavior affecting availability and integrity.
Prerequisites to Exploit
- Complex control flow paths that can lead to inconsistent lock management.
- Lack of proper exception handling for unlocking resources.
Vulnerable Code
def process_data(data):
resource = acquire_critical_resource()
try:
# Process data
if some_condition():
release_critical_resource(resource)
more_processing()
except Exception as e:
print("Exception occurred:", str(e))
release_critical_resource(resource)
Secure Code
def process_data(data):
resource = acquire_critical_resource()
try:
# Process data
if some_condition():
release_critical_resource(resource)
more_processing()
except Exception as e:
print("Exception occurred:", str(e))
finally:
release_critical_resource(resource)
The secure code ensures that the critical resource is properly released regardless of whether an exception occurs or not.
Business Impact of Multiple Unlocks of a Critical Resource
Availability:
- DoS conditions due to unexpected system states.
- Interruption in service availability leading to financial losses and customer dissatisfaction.
Integrity:
- Memory corruption affecting the integrity of data stored in critical resources.
- Unauthorized modifications or corruptions to sensitive data.
Multiple Unlocks of a Critical Resource Attack Scenario
- The attacker identifies a function that acquires and releases locks on critical resources within a web application.
- They exploit conditional logic or exceptions within the code to cause multiple unlocks, leading to an unexpected state in the system.
- This results in DoS conditions, memory corruption, or other unexpected behavior affecting availability and integrity.
How to Detect Multiple Unlocks of a Critical Resource
Manual Testing
- Review all locking mechanisms for proper unlocking procedures regardless of control flow paths.
- Ensure that exceptions are properly handled to release locks before exiting the function.
- [ ] Check if all control paths through the code correspond to exactly as many unlocks as there are locks.
- [ ] Verify that exception handling releases critical resources correctly.
Automated Scanners (SAST / DAST)
- Static analysis tools can detect patterns where locks and unlocks do not match across different control flows.
- Dynamic testing is necessary to validate actual runtime behavior under various conditions.
PenScan Detection
PenScan’s scanner engines such as ZAP, Nuclei, Wapiti, Nikto, SSLyze, Dalfox, and Nmap can identify instances of multiple unlocks in critical resources.
False Positive Guidance
False positives may occur if the pattern is present but not exploitable due to additional context (e.g., proper exception handling).
How to Fix Multiple Unlocks of a Critical Resource
- Ensure that each lock is paired with an unlock, regardless of control flow paths.
- Use try-finally blocks or similar constructs to ensure resources are released even if exceptions occur.
Framework-Specific Fixes for Multiple Unlocks of a Critical Resource
def process_data(data):
resource = acquire_critical_resource()
try:
# Process data
if some_condition():
release_critical_resource(resource)
more_processing()
except Exception as e:
print("Exception occurred:", str(e))
finally:
release_critical_resource(resource)
How to Ask AI to Check Your Code for Multiple Unlocks of a Critical Resource
Review the following Python code block for potential CWE-765 Multiple Unlocks of a Critical Resource vulnerabilities and rewrite it using proper locking mechanisms: [paste code here]
Multiple Unlocks of a Critical Resource Best Practices Checklist
✅ Ensure all control paths through the code release locks as many times as they acquire them. ✅ Use try-finally blocks to ensure resources are released even if exceptions occur. ✅ Avoid relying solely on try-catch blocks without ensuring that locks are properly released. ✅ Verify that exception handling releases critical resources correctly before exiting functions. ✅ Implement robust testing strategies to validate proper lock management under various conditions.
Multiple Unlocks of a Critical Resource FAQ
How does multiple unlocks of a critical resource occur?
It happens when a program or system unlocks a critical resource more times than intended, leading to an unexpected state in the system.
What are the consequences of multiple unlocks of a critical resource?
This can lead to DoS conditions, memory corruption, and unexpected behavior that affects both availability and integrity.
Can you provide real-world examples of this issue?
An example is when a program locks a file for writing but fails to unlock it correctly before exiting, leaving the file in an inconsistent state.
How can I detect multiple unlocks of a critical resource in my code?
Use static analysis tools and manual testing to check if all control paths through the code release locks as many times as they acquire them.
What are some best practices for preventing this issue?
Ensure that each lock is paired with an unlock, especially when dealing with exceptions or conditional logic.
How can I fix multiple unlocks of a critical resource in my existing codebase?
Review all locking mechanisms and ensure proper unlocking occurs regardless of the control flow path taken by the program.
What are some common mistakes to avoid when addressing this issue?
Avoid relying solely on try-catch blocks without ensuring that locks are properly released even if an exception is thrown.
Vulnerabilities Related to Multiple Unlocks of a Critical Resource
| CWE | Name | Relationship |
|---|---|---|
| CWE-667 | Improper Locking | ChildOf |
| CWE-675 | Multiple Operations on Resource in Single-Operation Context | ChildOf |
References
Scan Your Own Site
Manual code review catches what you know to look for. An automated scan catches what you didn’t. Scan your own website using PenScan to find Multiple Unlocks of a Critical Resource and other risks before an attacker does.