---
title: "CWE-667: Improper Locking"
url: https://radicalnotion.ai/cwe/cwe-667
type: cwe
description: "The product does not properly acquire or release a lock on a resource, leading to unexpected resource state changes and behaviors."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-667: Improper Locking

- **Abstraction:** Class
- **Structure:** Simple
- **Status:** Draft
- **CVEs with this as primary weakness:** 724
- **Of those, in CISA KEV:** 2
- **New in 2026:** 145
- **CWE catalog version:** 4.21

## Description

The product does not properly acquire or release a lock on a resource, leading to unexpected resource state changes and behaviors.

## Background

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.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Architecture and Design | - |
| Implementation | - |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Availability | DoS: Resource Consumption (CPU) | Inconsistent locking discipline can lead to deadlock. |
| Integrity | Modify Memory, Modify Application Data | This can lead to data or memory corruption. |
| Other | Varies by Context, Unexpected State | This can lead to unexpected resource state changes and behaviors. |

## Potential mitigations

### Implementation (Libraries or Frameworks)

Use industry standard APIs to implement locking mechanism.

## Detection methods

### 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

## Demonstrative examples

### 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:

```java
private 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:

```php
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().

### Example 3

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

Bad code:

```c
void f(pthread_mutex_t *mutex) {
    pthread_mutex_lock(mutex);

    /* access shared resource */

    pthread_mutex_unlock(mutex);
}
```

Good code:

```c
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);
}
```

### Example 4

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

Bad code:

```java
if (helper == null) {
    synchronized (this) {
        if (helper == null) {
            helper = new Helper();
        }
    }
}
return helper;
```

Bad code:

```java
helper = new Helper();
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2021-1782 | Chain: improper locking (CWE-667) leads to race condition (CWE-362), as exploited in the wild per CISA KEV. |
| CVE-2009-0935 | Attacker provides invalid address to a memory-reading function, causing a mutex to be unlocked twice |
| CVE-2010-4210 | function in OS kernel unlocks a mutex that was not previously locked, causing a panic or overwrite of arbitrary memory. |
| 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. |
| CVE-2009-1243 | OS kernel performs an unlock in some incorrect circumstances, leading to panic. |
| CVE-2009-2857 | OS deadlock |
| CVE-2009-1961 | OS deadlock involving 3 separate functions |
| CVE-2009-2699 | deadlock in library |
| CVE-2009-4272 | deadlock triggered by packets that force collisions in a routing table |
| CVE-2002-1850 | read/write deadlock between web server and script |
| CVE-2004-0174 | web server deadlock involving multiple listening connections |
| CVE-2009-1388 | multiple simultaneous calls to the same function trigger deadlock. |
| CVE-2006-5158 | Chain: other weakness leads to NULL pointer dereference (CWE-476) or deadlock (CWE-833). |
| CVE-2006-4342 | deadlock when an operation is performed on a resource while it is being removed. |
| CVE-2006-2374 | Deadlock in device driver triggered by using file handle of a related device. |
| CVE-2006-2275 | Deadlock when large number of small messages cannot be processed quickly enough. |
| CVE-2005-3847 | OS kernel has deadlock triggered by a signal during a core dump. |
| CVE-2005-3106 | Race condition leads to deadlock. |
| CVE-2005-2456 | Chain: array index error (CWE-129) leads to deadlock (CWE-833) |
| CVE-2001-0682 | Program can not execute when attacker obtains a mutex. |
| CVE-2002-1914 | Program can not execute when attacker obtains a lock on a critical output file. |
| CVE-2002-1915 | Program can not execute when attacker obtains a lock on a critical output file. |
| 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. |
| CVE-2000-0338 | Chain: predictable file names used for locking, allowing attacker to create the lock beforehand. Resultant from permissions and randomness. |
| CVE-2000-1198 | Chain: Lock files with predictable names. Resultant from randomness. |
| 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. |

## Real CVEs with this weakness (sample of 12 of 724)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2021-1782 | iOS and iPadOS: Kernel - A malicious application may be able to elevate privileges | high | 8.8 | - | Yes | 2021-04-02 |
| CVE-2025-43510 | iOS and iPadOS: Kernel - A malicious application may cause unexpected changes in memory shared between processes | high | 8.7 | - | Yes | 2025-12-12 |
| CVE-2021-22530 | Improper account management vulnerability in NetIQ Advance Authentication | critical | 9.9 | - | No | 2024-08-28 |
| CVE-2026-64232 | block: recompute nr\_integrity\_segments in blk\_insert\_cloned\_request | critical | 9.8 | - | No | 2026-07-24 |
| CVE-2026-64068 | netfs: Fix missing locking around retry adding new subreqs | critical | 9.8 | - | No | 2026-07-19 |
| CVE-2026-64067 | netfs: Fix missing barriers when accessing stream-\>subrequests locklessly | critical | 9.8 | - | No | 2026-07-19 |
| CVE-2025-39910 | mm/vmalloc, mm/kasan: respect gfp mask in kasan\_populate\_vmalloc() | critical | 9.8 | - | No | 2025-10-01 |
| CVE-2025-22077 | Revert "smb: client: fix TCP timers deadlock after rmmod" | critical | 9.8 | - | No | 2025-04-16 |
| CVE-2024-58087 | ksmbd: fix racy issue from session lookup and expire | critical | 9.8 | - | No | 2025-03-12 |
| CVE-2024-41081 | ila: block BH in ila\_output() | critical | 9.8 | - | No | 2024-07-29 |
| CVE-2021-47587 | net: systemport: Add global locking for descriptor lifecycle | critical | 9.8 | - | No | 2024-06-19 |
| CVE-2024-32900 | - | critical | 9.8 | - | No | 2024-06-13 |

## Related attack patterns (CAPEC)

- [CAPEC-25](https://radicalnotion.ai/capec/capec-25): Forced Deadlock
- [CAPEC-26](https://radicalnotion.ai/capec/capec-26): Leveraging Race Conditions
- [CAPEC-27](https://radicalnotion.ai/capec/capec-27): Leveraging Race Conditions via Symbolic Links

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-662](https://radicalnotion.ai/cwe/cwe-662) | Improper Synchronization |
| Child | [CWE-412](https://radicalnotion.ai/cwe/cwe-412) | Unrestricted Externally Accessible Lock |
| Child | [CWE-413](https://radicalnotion.ai/cwe/cwe-413) | Improper Resource Locking |
| Child | [CWE-414](https://radicalnotion.ai/cwe/cwe-414) | Missing Lock Check |
| Child | [CWE-609](https://radicalnotion.ai/cwe/cwe-609) | Double-Checked Locking |
| Child | [CWE-764](https://radicalnotion.ai/cwe/cwe-764) | Multiple Locks of a Critical Resource |
| Child | [CWE-765](https://radicalnotion.ai/cwe/cwe-765) | Multiple Unlocks of a Critical Resource |
| Child | [CWE-832](https://radicalnotion.ai/cwe/cwe-832) | Unlock of a Resource that is not Locked |
| Child | [CWE-833](https://radicalnotion.ai/cwe/cwe-833) | Deadlock |
| Child | [CWE-1232](https://radicalnotion.ai/cwe/cwe-1232) | Improper Lock Behavior After Power State Transition |
| Child | [CWE-1233](https://radicalnotion.ai/cwe/cwe-1233) | Security-Sensitive Hardware Controls with Missing Lock Bit Protection |
| Child | [CWE-1234](https://radicalnotion.ai/cwe/cwe-1234) | Hardware Internal or Debug Modes Allow Override of Locks |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CERT C Secure Coding | Do not destroy a mutex while it is locked | CON31-C | CWE More Abstract |
| CERT C Secure Coding | Do not unlock or destroy another POSIX thread's mutex | POS48-C | CWE More Abstract |
| The CERT Oracle Secure Coding Standard for Java (2011) | Ensure visibility when accessing shared primitive variables | VNA00-J | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Ensure that compound operations on shared variables are atomic | VNA02-J | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Ensure atomicity when reading and writing 64-bit values | VNA05-J | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Do not use an instance lock to protect shared static data | LCK06-J | - |
| Software Fault Patterns | Missing Lock | SFP19 | - |
| OMG ASCSM | - | ASCSM-CWE-667 | - |

## Frequently asked questions

### What is CWE-667?

The product does not properly acquire or release a lock on a resource, leading to unexpected resource state changes and behaviors.

### What CVEs are caused by CWE-667?

724 recorded CVEs are attributed to CWE-667, including CVE-2021-1782, CVE-2025-43510 and CVE-2021-22530. 2 are listed in CISA's Known Exploited Vulnerabilities (KEV) catalog.

### How do you prevent CWE-667?

Use industry standard APIs to implement locking mechanism.

### How is CWE-667 detected?

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

### What are the consequences of CWE-667?

Exploiting CWE-667 can lead to: DoS: Resource Consumption (CPU), Modify Memory, Modify Application Data, Varies by Context, Unexpected State.

### Is CWE-667 actively exploited?

Yes. 2 CWE-667 vulnerabilities are in CISA's KEV catalog of actively exploited flaws, out of 724 recorded CVEs.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/667.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-667). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
