CWE-662 Class Draft

Improper Synchronization

This vulnerability occurs when a multi-threaded or multi-process application allows shared resources to be accessed by multiple threads or processes simultaneously, without proper safeguards to…

Definition

What is CWE-662?

This vulnerability occurs when a multi-threaded or multi-process application allows shared resources to be accessed by multiple threads or processes simultaneously, without proper safeguards to enforce exclusive access.
Synchronization is the set of techniques that prevent multiple threads or processes from interfering with each other when they need to use the same resource, like a variable, file, or memory location. Since many operations on these resources cannot be performed in a single, atomic step, you need mechanisms like locks, mutexes, or semaphores to guarantee that one thread completes its entire sequence of operations before another can begin. Without this coordination, the application's behavior becomes unpredictable and unstable. Improper synchronization directly leads to race conditions, where the final state of the resource depends on the unpredictable timing of thread execution. This can corrupt data, crash the program, create security bypasses, or cause a denial of service. As a developer, you must identify all shared resources in your concurrent code and explicitly protect them with appropriate synchronization primitives to ensure only one thread can access them at a time.
Real-world impact

Real-world CVEs caused by CWE-662

  • Chain: improper locking (CWE-667) leads to race condition (CWE-362), as exploited in the wild per CISA KEV.

  • Attacker provides invalid address to a memory-reading function, causing a mutex to be unlocked twice

How attackers exploit it

Step-by-step attacker path

  1. 1

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

  2. 2

    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.

  3. 3

    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.

  4. 4

    The following code intends to fork a process, then have both the parent and child processes print a single line.

  5. 5

    One might expect the code to print out something like:

Vulnerable code example

Vulnerable C

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

Vulnerable C
void f(pthread_mutex_t *mutex) {
  		pthread_mutex_lock(mutex);
```
/* access shared resource */* 
  		
  		
  		pthread_mutex_unlock(mutex);}
Secure code example

Secure C

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.

Secure 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);}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Prevention checklist

How to prevent CWE-662

  • Implementation Use industry standard APIs to synchronize your code.
Detection signals

How to detect CWE-662

SAST High

Run static analysis (SAST) on the codebase looking for the unsafe pattern in the data flow.

DAST Moderate

Run dynamic application security testing against the live endpoint.

Runtime Moderate

Watch runtime logs for unusual exception traces, malformed input, or authorization bypass attempts.

Code review Moderate

Code review: flag any new code that handles input from this surface without using the validated framework helpers.

Plexicus auto-fix

Plexicus auto-detects CWE-662 and opens a fix PR in under 60 seconds.

Codex Remedium scans every commit, identifies this exact weakness, and ships a reviewer-ready pull request with the patch. No tickets. No hand-offs.

Frequently asked questions

Frequently asked questions

What is CWE-662?

This vulnerability occurs when a multi-threaded or multi-process application allows shared resources to be accessed by multiple threads or processes simultaneously, without proper safeguards to enforce exclusive access.

How serious is CWE-662?

MITRE has not published a likelihood-of-exploit rating for this weakness. Treat it as medium-impact until your threat model proves otherwise.

What languages or platforms are affected by CWE-662?

MITRE has not specified affected platforms for this CWE — it can apply across most application stacks.

How can I prevent CWE-662?

Use industry standard APIs to synchronize your code.

How does Plexicus detect and fix CWE-662?

Plexicus's SAST engine matches the data-flow signature for CWE-662 on every commit. When a match is found, our Codex Remedium agent opens a fix PR with the corrected code, tests, and a one-line summary for the reviewer.

Where can I learn more about CWE-662?

MITRE publishes the canonical definition at https://cwe.mitre.org/data/definitions/662.html. You can also reference OWASP and NIST documentation for adjacent guidance.

Related weaknesses

Weaknesses related to CWE-662

CWE-664 Parent

Improper Control of a Resource Through its Lifetime

This vulnerability occurs when software fails to properly manage a resource throughout its entire lifecycle—from creation and active use…

CWE-118 Sibling

Incorrect Access of Indexable Resource ('Range Error')

This vulnerability occurs when software fails to properly check the boundaries of an indexed resource, like an array, buffer, or file,…

CWE-1229 Sibling

Creation of Emergent Resource

This vulnerability occurs when a system's normal operations unintentionally create new, exploitable resources that attackers can use to…

CWE-1250 Sibling

Improper Preservation of Consistency Between Independent Representations of Shared State

This vulnerability occurs when a system with multiple independent components (like distributed services or separate hardware units) each…

CWE-1329 Sibling

Reliance on Component That is Not Updateable

This vulnerability occurs when a product depends on a component that cannot be updated or patched to fix security flaws or critical bugs.

CWE-221 Sibling

Information Loss or Omission

This weakness occurs when an application fails to log critical security events or records them inaccurately, which can misguide security…

CWE-372 Sibling

Incomplete Internal State Distinction

This vulnerability occurs when an application fails to accurately track its own operational state. The system incorrectly assumes it's in…

CWE-400 Sibling

Uncontrolled Resource Consumption

This vulnerability occurs when an application fails to properly manage a finite resource, allowing an attacker to exhaust it and cause a…

CWE-404 Sibling

Improper Resource Shutdown or Release

This vulnerability occurs when a program fails to properly close or release a system resource—like a file handle, database connection, or…

Ready when you are

Don't Let Security
Weigh You Down.

Stop choosing between AI velocity and security debt. Plexicus is the only platform that runs Vibe Coding Security and ASPM in parallel — one workflow, every codebase.