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.

Primary

Architecture and Design

Implementation

Availability
DoS: Resource Consumption (CPU)
Inconsistent locking discipline can lead to deadlock.

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.)
High

Implementation
Libraries or Frameworks
Use industry standard APIs to implement locking mechanism.

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.

private long someLongValue;public long getLongValue() {return someLongValue;}
public void setLongValue(long l) {someLongValue = l;}

This code tries to obtain a lock for a file, then writes to it.

function 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().

The following function attempts to acquire a lock in order to perform operations on a shared resource.

void 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.

int 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);
}

It may seem that the following bit of code achieves thread safety while avoiding unnecessary synchronization...

if (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:

helper = 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.

CVE-2021-1782
Chain: improper locking (CWE-667) leads to race condition (CWE-362), as exploited in the wild per CISA KEV.
https://www.cve.org/CVERecord?id=CVE-2021-1782

CVE-2009-0935
Attacker provides invalid address to a memory-reading function, causing a mutex to be unlocked twice
https://www.cve.org/CVERecord?id=CVE-2009-0935

CVE-2010-4210
function in OS kernel unlocks a mutex that was not previously locked, causing a panic or overwrite of arbitrary memory.
https://www.cve.org/CVERecord?id=CVE-2010-4210

CVE-2008-4302
Chain: OS kernel does not properly handle a failure of a function call (CWE-755), leading to an unlock of a resource that was not locked (CWE-832), with resultant crash.
https://www.cve.org/CVERecord?id=CVE-2008-4302

CVE-2009-1243
OS kernel performs an unlock in some incorrect circumstances, leading to panic.
https://www.cve.org/CVERecord?id=CVE-2009-1243

CVE-2009-2857
OS deadlock
https://www.cve.org/CVERecord?id=CVE-2009-2857

CVE-2009-1961
OS deadlock involving 3 separate functions
https://www.cve.org/CVERecord?id=CVE-2009-1961

CVE-2009-2699
deadlock in library
https://www.cve.org/CVERecord?id=CVE-2009-2699

CVE-2009-4272
deadlock triggered by packets that force collisions in a routing table
https://www.cve.org/CVERecord?id=CVE-2009-4272

CVE-2002-1850
read/write deadlock between web server and script
https://www.cve.org/CVERecord?id=CVE-2002-1850

CVE-2004-0174
web server deadlock involving multiple listening connections
https://www.cve.org/CVERecord?id=CVE-2004-0174

CVE-2009-1388
multiple simultaneous calls to the same function trigger deadlock.
https://www.cve.org/CVERecord?id=CVE-2009-1388

CVE-2006-5158
chain: other weakness leads to NULL pointer dereference (CWE-476) or deadlock (CWE-833).
https://www.cve.org/CVERecord?id=CVE-2006-5158

CVE-2006-4342
deadlock when an operation is performed on a resource while it is being removed.
https://www.cve.org/CVERecord?id=CVE-2006-4342

CVE-2006-2374
Deadlock in device driver triggered by using file handle of a related device.
https://www.cve.org/CVERecord?id=CVE-2006-2374

CVE-2006-2275
Deadlock when large number of small messages cannot be processed quickly enough.
https://www.cve.org/CVERecord?id=CVE-2006-2275

CVE-2005-3847
OS kernel has deadlock triggered by a signal during a core dump.
https://www.cve.org/CVERecord?id=CVE-2005-3847

CVE-2005-3106
Race condition leads to deadlock.
https://www.cve.org/CVERecord?id=CVE-2005-3106

CVE-2005-2456
Chain: array index error (CWE-129) leads to deadlock (CWE-833)
https://www.cve.org/CVERecord?id=CVE-2005-2456

CVE-2001-0682
Program can not execute when attacker obtains a mutex.
https://www.cve.org/CVERecord?id=CVE-2001-0682

CVE-2002-1914
Program can not execute when attacker obtains a lock on a critical output file.
https://www.cve.org/CVERecord?id=CVE-2002-1914

CVE-2002-1915
Program can not execute when attacker obtains a lock on a critical output file.
https://www.cve.org/CVERecord?id=CVE-2002-1915

CVE-2002-0051
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.
https://www.cve.org/CVERecord?id=CVE-2002-0051

CVE-2000-0338
Chain: predictable file names used for locking, allowing attacker to create the lock beforehand. Resultant from permissions and randomness.
https://www.cve.org/CVERecord?id=CVE-2000-0338

CVE-2000-1198
Chain: Lock files with predictable names. Resultant from randomness.
https://www.cve.org/CVERecord?id=CVE-2000-1198

CVE-2002-1869
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.
https://www.cve.org/CVERecord?id=CVE-2002-1869

CON31-C
Do not destroy a mutex while it is locked
CWE More Abstract

POS48-C
Do not unlock or destroy another POSIX thread's mutex
CWE More Abstract

VNA00-J
Ensure visibility when accessing shared primitive variables

VNA02-J
Ensure that compound operations on shared variables are atomic

VNA05-J
Ensure atomicity when reading and writing 64-bit values

LCK06-J
Do not use an instance lock to protect shared static data

SFP19
Missing Lock

ASCSM-CWE-667

Allowed-with-Review
This CWE entry is a Class and might have Base-level children that would be more appropriate
Examine children of this entry to see if there is a better fit

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.

CWE Content Team
MITRE
2008-04-11
Draft 9
2008-04-11

Sean Eidemiller
Cigital
2008-07-01
added/updated demonstrative examples

Eric Dalci
Cigital
2008-07-01
updated Potential_Mitigations, Time_of_Introduction

CWE Content Team
MITRE
2008-09-08
updated Relationships

CWE Content Team
MITRE
2008-11-24
updated Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2009-03-10
updated Related_Attack_Patterns

CWE Content Team
MITRE
2009-05-27
updated Relationships

CWE Content Team
MITRE
2009-07-27
updated Common_Consequences

CWE Content Team
MITRE
2010-09-27
updated Relationships

CWE Content Team
MITRE
2010-12-13
updated Description, Name, Relationships

CWE Content Team
MITRE
2011-06-01
updated Common_Consequences, Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2012-05-11
updated Demonstrative_Examples, Observed_Examples, Relationships

CWE Content Team
MITRE
2012-10-30
updated Potential_Mitigations

CWE Content Team
MITRE
2014-07-30
updated Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2017-05-03
updated Related_Attack_Patterns

CWE Content Team
MITRE
2017-11-08
updated Taxonomy_Mappings

CWE Content Team
MITRE
2019-01-03
updated References, Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2019-09-19
updated Relationships

CWE Content Team
MITRE
2019-09-23
updated Description, Maintenance_Notes, Relationships

CWE Content Team
MITRE
2020-02-24
updated Relationships, Type

CWE Content Team
MITRE
2020-08-20
updated Relationships

CWE Content Team
MITRE
2020-12-10
updated Relationships

CWE Content Team
MITRE
2021-03-15
updated Demonstrative_Examples

CWE Content Team
MITRE
2022-06-28
updated Observed_Examples

CWE Content Team
MITRE
2023-01-31
updated Description

CWE Content Team
MITRE
2023-04-27
updated Detection_Factors, Relationships

CWE Content Team
MITRE
2023-06-29
updated Mapping_Notes

CWE Content Team
MITRE
2025-04-03
4.17
2025-04-03
updated Demonstrative_Examples

CWE Content Team
MITRE
2025-12-11
4.19
2025-12-11
updated Applicable_Platforms, Weakness_Ordinalities

Insufficient Locking