- Home
-
CWE-667: Improper Locking
Weakness ID: 667Vulnerability Mapping: ALLOWED This CWE ID could be used to map to real-world vulnerabilities in limited situations requiring careful review (with careful review of mapping notes)
Abstraction: Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource.View customized information:For users who are interested in more notional aspects of a weakness. Example: educators, technical writers, and project/program managers. For users who are concerned with the practical application and details about the nature of a weakness and how to prevent it from happening. Example: tool developers, security researchers, pen-testers, incident response analysts. For users who are mapping an issue to CWE/CAPEC IDs, i.e., finding the most appropriate CWE for a specific issue (e.g., a CVE record). Example: tool developers, security researchers. For users who wish to see all available information for the CWE/CAPEC entry. For users who want to customize what details are displayed.×
Edit Custom Filter
The product does not properly acquire or release a lock on a resource, leading to unexpected resource state changes and behaviors.Locking is a type of synchronization behavior that ensures that multiple independently-operating processes or threads do not interfere with each other when accessing the same resource. All processes/threads are expected to follow the same steps for locking. If these steps are not followed precisely - or if no locking is done at all - then another process/thread could modify the shared resource in a way that is not visible or predictable to the original process. This can lead to data or memory corruption, denial of service, etc.
This table specifies different individual consequences
associated with the weakness. The Scope identifies the application security area that is
violated, while the Impact describes the negative technical impact that arises if an
adversary succeeds in exploiting this weakness. The Likelihood provides information about
how likely the specific consequence is expected to be seen relative to the other
consequences in the list. For example, there may be high likelihood that a weakness will be
exploited to achieve a certain impact, but a low likelihood that it will be exploited to
achieve a different impact.
Impact Details DoS: Resource Consumption (CPU)
Scope: Availability Inconsistent locking discipline can lead to deadlock.Phase(s) Mitigation Implementation
Strategy: Libraries or Frameworks
Use industry standard APIs to implement locking mechanism.
This table shows the weaknesses and high level categories that are related to this
weakness. These relationships are defined as ChildOf, ParentOf, MemberOf and give insight to
similar items that may exist at higher and lower levels of abstraction. In addition,
relationships such as PeerOf and CanAlsoBe are defined to show similar weaknesses that the user
may want to explore.
Relevant to the view "Research Concepts" (View-1000)
Nature Type ID Name ChildOf
Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource.
662 Improper Synchronization ParentOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
412 Unrestricted Externally Accessible Lock ParentOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
413 Improper Resource Locking ParentOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
414 Missing Lock Check ParentOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
609 Double-Checked Locking ParentOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
764 Multiple Locks of a Critical Resource ParentOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
765 Multiple Unlocks of a Critical Resource ParentOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
832 Unlock of a Resource that is not Locked ParentOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
833 Deadlock ParentOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
1232 Improper Lock Behavior After Power State Transition ParentOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
1233 Security-Sensitive Hardware Controls with Missing Lock Bit Protection ParentOf
Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
1234 Hardware Internal or Debug Modes Allow Override of Locks
Relevant to the view "Weaknesses for Simplified Mapping of Published Vulnerabilities" (View-1003)
Nature Type ID Name ChildOf
Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource.
662 Improper Synchronization
Relevant to the view "CISQ Quality Measures (2020)" (View-1305)
Nature Type ID Name ChildOf
Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource.
662 Improper Synchronization
Relevant to the view "CISQ Data Protection Measures" (View-1340)
Nature Type ID Name ChildOf
Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource.
662 Improper Synchronization
The different Modes of Introduction provide information
about how and when this
weakness may be introduced. The Phase identifies a point in the life cycle at which
introduction
may occur, while the Note provides a typical scenario related to introduction during the
given
phase.
Phase Note Architecture and Design Implementation
This listing shows possible areas for which the given
weakness could appear. These
may be for specific named Languages, Operating Systems, Architectures, Paradigms,
Technologies,
or a class of such platforms. The platform is listed along with how frequently the given
weakness appears for that instance.
Languages Class: Not Language-Specific (Undetermined Prevalence)
Technologies Class: Not Technology-Specific (Undetermined Prevalence)
Example 1
In the following Java snippet, methods are defined to get and set a long field in an instance of a class that is shared across multiple threads. Because operations on double and long are nonatomic in Java, concurrent access may cause unexpected behavior. Thus, all operations on long and double fields should be synchronized.
(bad code)Example Language: Javaprivate long someLongValue;
public long getLongValue() {return someLongValue;}
public void setLongValue(long l) {someLongValue = l;}
Example 2
This code tries to obtain a lock for a file, then writes to it.
(bad code)Example Language: PHPfunction writeToLog($message){$logfile = fopen("logFile.log", "a");}
//attempt to get logfile lock
if (flock($logfile, LOCK_EX)) {fwrite($logfile,$message);}
// unlock logfile
flock($logfile, LOCK_UN);
else {print "Could not obtain lock on logFile.log, message not recorded\n";}
fclose($logFile);PHP by default will wait indefinitely until a file lock is released. If an attacker is able to obtain the file lock, this code will pause execution, possibly leading to denial of service for other users. Note that in this case, if an attacker can perform an flock() on the file, they may already have privileges to destroy the log file. However, this still impacts the execution of other programs that depend on flock().
Example 3
The following function attempts to acquire a lock in order to perform operations on a shared resource.
(bad code)Example Language: Cvoid f(pthread_mutex_t *mutex) {}pthread_mutex_lock(mutex);
/* access shared resource */
pthread_mutex_unlock(mutex);However, the code does not check the value returned by pthread_mutex_lock() for errors. If pthread_mutex_lock() cannot acquire the mutex for any reason, the function may introduce a race condition into the program and result in undefined behavior.
In order to avoid data races, correctly written programs must check the result of thread synchronization functions and appropriately handle all errors, either by attempting to recover from them or reporting them to higher levels.
(good code)Example Language: Cint f(pthread_mutex_t *mutex) {}int result;
result = pthread_mutex_lock(mutex);
if (0 != result)return result;
/* access shared resource */
return pthread_mutex_unlock(mutex);
Example 4
It may seem that the following bit of code achieves thread safety while avoiding unnecessary synchronization...
(bad code)Example Language: Javaif (helper == null) {}synchronized (this) {if (helper == null) {}helper = new Helper();}
return helper;The programmer wants to guarantee that only one Helper() object is ever allocated, but does not want to pay the cost of synchronization every time this code is called.
Suppose that helper is not initialized. Then, thread A sees that helper==null and enters the synchronized block and begins to execute:
(bad code)Example Language: Javahelper = new Helper();If a second thread, thread B, takes over in the middle of this call and helper has not finished running the constructor, then thread B may make calls on helper while its fields hold incorrect values.
Note: this is a curated list of examples for users to understand the variety of ways in which this weakness can be introduced. It is not a complete list of all CVEs that are related to this CWE entry.
Reference Description Attacker provides invalid address to a memory-reading function, causing a mutex to be unlocked twicefunction in OS kernel unlocks a mutex that was not previously locked, causing a panic or overwrite of arbitrary memory.OS kernel performs an unlock in some incorrect circumstances, leading to panic.OS deadlockOS deadlock involving 3 separate functionsdeadlock in librarydeadlock triggered by packets that force collisions in a routing tableread/write deadlock between web server and scriptweb server deadlock involving multiple listening connectionsmultiple simultaneous calls to the same function trigger deadlock.deadlock when an operation is performed on a resource while it is being removed.Deadlock in device driver triggered by using file handle of a related device.Deadlock when large number of small messages cannot be processed quickly enough.OS kernel has deadlock triggered by a signal during a core dump.Race condition leads to deadlock.Program can not execute when attacker obtains a mutex.Program can not execute when attacker obtains a lock on a critical output file.Program can not execute when attacker obtains a lock on a critical output file.Critical file can be opened with exclusive read access by user, preventing application of security policy. Possibly related to improper permissions, large-window race condition.Chain: predictable file names used for locking, allowing attacker to create the lock beforehand. Resultant from permissions and randomness.Chain: Lock files with predictable names. Resultant from randomness.Product does not check if it can write to a log file, allowing attackers to avoid logging by accessing the file using an exclusive lock. Overlaps unchecked error condition. This is not quite CWE-412, but close.Ordinality Description Primary(where the weakness exists independent of other weaknesses)Method Details 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.)Effectiveness: High
This MemberOf Relationships table shows additional CWE Categories and Views that
reference this weakness as a member. This information is often useful in understanding where a
weakness fits within the context of external information sources.
Nature Type ID Name MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.748 CERT C Secure Coding Standard (2008) Appendix - POSIX (POS) MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.852 The CERT Oracle Secure Coding Standard for Java (2011) Chapter 9 - Visibility and Atomicity (VNA) MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.853 The CERT Oracle Secure Coding Standard for Java (2011) Chapter 10 - Locking (LCK) MemberOf
View - a subset of CWE entries that provides a way of examining CWE content. The two main view structures are Slices (flat lists) and Graphs (containing relationships between entries).884 CWE Cross-section MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.986 SFP Secondary Cluster: Missing Lock MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.1131 CISQ Quality Measures (2016) - Security MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.1142 SEI CERT Oracle Secure Coding Standard for Java - Guidelines 08. Visibility and Atomicity (VNA) MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.1143 SEI CERT Oracle Secure Coding Standard for Java - Guidelines 09. Locking (LCK) MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.1169 SEI CERT C Coding Standard - Guidelines 14. Concurrency (CON) MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.1171 SEI CERT C Coding Standard - Guidelines 50. POSIX (POS) MemberOf
Category - a CWE entry that contains a set of other entries that share a common characteristic.1401 Comprehensive Categorization: Concurrency Usage ALLOWED-WITH-REVIEW (this CWE ID could be used to map to real-world vulnerabilities in limited situations requiring careful review)Reason Abstraction Rationale
This CWE entry is a Class and might have Base-level children that would be more appropriate Comments
Examine children of this entry to see if there is a better fit Maintenance
Deeper research is necessary for synchronization and related mechanisms, including locks, mutexes, semaphores, and other mechanisms. Multiple entries are dependent on this research, which includes relationships to concurrency, race conditions, reentrant functions, etc. CWE-662 and its children - including CWE-667, CWE-820, CWE-821, and others - may need to be modified significantly, along with their relationships.Mapped Taxonomy Name Node ID Fit Mapped Node Name CERT C Secure Coding CON31-C CWE More Abstract Do not destroy a mutex while it is locked CERT C Secure Coding POS48-C CWE More Abstract Do not unlock or destroy another POSIX thread's mutex The CERT Oracle Secure Coding Standard for Java (2011) VNA00-J Ensure visibility when accessing shared primitive variables The CERT Oracle Secure Coding Standard for Java (2011) VNA02-J Ensure that compound operations on shared variables are atomic The CERT Oracle Secure Coding Standard for Java (2011) VNA05-J Ensure atomicity when reading and writing 64-bit values The CERT Oracle Secure Coding Standard for Java (2011) LCK06-J Do not use an instance lock to protect shared static data Software Fault Patterns SFP19 Missing Lock OMG ASCSM ASCSM-CWE-667 [REF-962] Object Management Group (OMG). "Automated Source Code Security Measure (ASCSM)". ASCSM-CWE-667. 2016-01.
<http://www.omg.org/spec/ASCSM/1.0/>.More information is available — Please edit the custom filter or select a different filter.Page Last Updated: January 21, 2026Use of the Common Weakness Enumeration (CWE™) and the associated references from this website are subject to the Terms of Use. CWE is sponsored by the U.S. Department of Homeland Security (DHS) Cybersecurity and Infrastructure Security Agency (CISA) and managed by the Homeland Security Systems Engineering and Development Institute (HSSEDI) which is operated by The MITRE Corporation (MITRE). Copyright © 2006–2026, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation.



