CWE - CWE-662: Improper Synchronization (4.19.1)
Weakness ID: 662
Vulnerability Mapping: DISCOURAGED This CWE ID should not be used to map to real-world vulnerabilitiesAbstraction: 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.
Description
The product utilizes multiple threads, processes, components, or systems to allow temporary access to a shared resource that can only be exclusive to one process at a time, but it does not properly synchronize these actions, which might cause simultaneous accesses of this resource by multiple threads or processes.
Extended Description
Synchronization refers to a variety of behaviors and mechanisms that allow two or more independently-operating processes or threads to ensure that they operate on shared resources in predictable ways that do not interfere with each other. Some shared resource operations cannot be executed atomically; that is, multiple steps must be guaranteed to execute sequentially, without any interference by other processes. Synchronization mechanisms vary widely, but they may include locking, mutexes, and semaphores. When a multi-step operation on a shared resource cannot be guaranteed to execute independent of interference, then the resulting behavior can be unpredictable. Improper synchronization could lead to data or memory corruption, denial of service, etc.
Common Consequences
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 |
|---|---|
|
Modify Application Data; Read Application Data; Alter Execution Logic |
Scope: Integrity, Confidentiality, Other |
Potential Mitigations
| Phase(s) | Mitigation |
|---|---|
|
Implementation |
Use industry standard APIs to synchronize your code. |
Relationships
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 |
|
664 | Improper Control of a Resource Through its Lifetime |
| ChildOf |
|
691 | Insufficient Control Flow Management |
| ParentOf |
|
362 | Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition') |
| ParentOf |
|
663 | Use of a Non-reentrant Function in a Concurrent Context |
| ParentOf |
|
667 | Improper Locking |
| ParentOf |
|
820 | Missing Synchronization |
| ParentOf |
|
821 | Incorrect Synchronization |
| ParentOf |
|
1058 | Invokable Control Element in Multi-Thread Context with non-Final Static Storable or Member Element |
| ParentOf |
|
1265 | Unintended Reentrant Invocation of Non-reentrant Code Via Nested Calls |
| CanPrecede |
|
362 | Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition') |
Relevant to the view "Weaknesses for Simplified Mapping of Published Vulnerabilities" (View-1003)
Relevant to the view "CISQ Quality Measures (2020)" (View-1305)
| Nature | Type | ID | Name |
|---|---|---|---|
| ParentOf |
|
366 | Race Condition within a Thread |
| ParentOf |
|
543 | Use of Singleton Pattern Without Synchronization in a Multithreaded Context |
| ParentOf |
|
567 | Unsynchronized Access to Shared Data in a Multithreaded Context |
| ParentOf |
|
667 | Improper Locking |
| ParentOf |
|
764 | Multiple Locks of a Critical Resource |
| ParentOf |
|
820 | Missing Synchronization |
| ParentOf |
|
821 | Incorrect Synchronization |
| ParentOf |
|
833 | Deadlock |
| ParentOf |
|
1058 | Invokable Control Element in Multi-Thread Context with non-Final Static Storable or Member Element |
| ParentOf |
|
1096 | Singleton Class Instance Creation without Proper Locking or Synchronization |
Relevant to the view "CISQ Data Protection Measures" (View-1340)
| Nature | Type | ID | Name |
|---|---|---|---|
| ParentOf |
|
366 | Race Condition within a Thread |
| ParentOf |
|
543 | Use of Singleton Pattern Without Synchronization in a Multithreaded Context |
| ParentOf |
|
567 | Unsynchronized Access to Shared Data in a Multithreaded Context |
| ParentOf |
|
667 | Improper Locking |
| ParentOf |
|
764 | Multiple Locks of a Critical Resource |
| ParentOf |
|
820 | Missing Synchronization |
| ParentOf |
|
821 | Incorrect Synchronization |
| ParentOf |
|
1058 | Invokable Control Element in Multi-Thread Context with non-Final Static Storable or Member Element |
| ParentOf |
|
1096 | Singleton Class Instance Creation without Proper Locking or Synchronization |
Modes
Of Introduction
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 |
Applicable Platforms
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) |
Demonstrative Examples
Example 1
The following function attempts to acquire a lock in order to perform operations on a shared resource.
(bad code)
Example Language: C
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.
(good code)
Example Language: 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 2
The following code intends to fork a process, then have both the parent and child processes print a single line.
(bad code)
Example Language: C
static void print (char * string) {
char * word;
int counter;
for (word = string; counter = *word++; ) {
putc(counter, stdout);
fflush(stdout);
/* Make timing window a little larger... */
sleep(1);
}
}
int main(void) {
pid_t pid;
pid = fork();
if (pid == -1) {
exit(-2);
}
else if (pid == 0) {
print("child\n");
}
else {
print("PARENT\n");
}
exit(0);
}
One might expect the code to print out something like:
However, because the parent and child are executing concurrently, and stdout is flushed each time a character is printed, the output might be mixed together, such as:
PcAhRiElNdT
[blank line]
[blank line]
Selected Observed
Examples
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.
Weakness Ordinalities
| Ordinality | Description |
|---|---|
|
Primary |
(where the weakness exists independent of other weaknesses) |
Detection
Methods
| 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.) |
Memberships
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.
Vulnerability Mapping Notes
| Usage |
DISCOURAGED
(this CWE ID should not be used to map to real-world vulnerabilities) |
| Reason | Abstraction |
|
Rationale |
This CWE entry is a level-1 Class (i.e., a child of a Pillar). It might have lower-level children that would be more appropriate |
|
Comments |
Examine children of this entry to see if there is a better fit |
Notes
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.
Taxonomy
Mappings
| Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
|---|---|---|---|
| CERT C Secure Coding | SIG00-C | Mask signals handled by noninterruptible signal handlers | |
| CERT C Secure Coding | SIG31-C | CWE More Abstract | Do not access shared objects in signal handlers |
| CLASP | State synchronization error | ||
| The CERT Oracle Secure Coding Standard for Java (2011) | VNA03-J | Do not assume that a group of calls to independently atomic methods is atomic | |
| Software Fault Patterns | SFP19 | Missing Lock |
Content
History
Submissions |
|||
|---|---|---|---|
| Submission Date | Submitter | Organization | |
|
2008-04-11
(CWE Draft 9, 2008-04-11) |
CWE Community | ||
| Submitted by members of the CWE community to extend early CWE versions | |||
Modifications |
|||
| Modification Date | Modifier | Organization | |
|
2025-12-11
(CWE 4.19, 2025-12-11) |
CWE Content Team | MITRE | |
| updated Applicable_Platforms, Description, Detection_Factors, Relationships, Weakness_Ordinalities | |||
|
2024-02-29
(CWE 4.14, 2024-02-29) |
CWE Content Team | MITRE | |
| updated Mapping_Notes | |||
| 2023-10-26 | CWE Content Team | MITRE | |
| updated Demonstrative_Examples, Observed_Examples | |||
| 2023-06-29 | CWE Content Team | MITRE | |
| updated Mapping_Notes | |||
| 2023-04-27 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2023-01-31 | CWE Content Team | MITRE | |
| updated Description | |||
| 2020-12-10 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2020-08-20 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2020-02-24 | CWE Content Team | MITRE | |
| updated Description, Relationships | |||
| 2019-09-23 | CWE Content Team | MITRE | |
| updated Description, Maintenance_Notes, Relationships | |||
| 2019-06-20 | CWE Content Team | MITRE | |
| updated Type | |||
| 2019-01-03 | CWE Content Team | MITRE | |
| updated Relationships, Taxonomy_Mappings | |||
| 2017-11-08 | CWE Content Team | MITRE | |
| updated Taxonomy_Mappings | |||
| 2014-07-30 | CWE Content Team | MITRE | |
| updated Relationships, Taxonomy_Mappings | |||
| 2013-07-17 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2012-10-30 | CWE Content Team | MITRE | |
| updated Potential_Mitigations | |||
| 2012-05-11 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2011-09-13 | CWE Content Team | MITRE | |
| updated Relationships, Taxonomy_Mappings | |||
| 2011-06-01 | CWE Content Team | MITRE | |
| updated Common_Consequences, Relationships, Taxonomy_Mappings | |||
| 2010-12-13 | CWE Content Team | MITRE | |
| updated Description, Relationships, Taxonomy_Mappings | |||
| 2010-09-27 | CWE Content Team | MITRE | |
| updated Name, Relationships | |||
| 2009-05-27 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2009-03-10 | CWE Content Team | MITRE | |
| updated Related_Attack_Patterns | |||
| 2008-11-24 | CWE Content Team | MITRE | |
| updated Relationships, Taxonomy_Mappings | |||
| 2008-10-14 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2008-09-08 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2008-07-01 | Eric Dalci | Cigital | |
| updated Potential_Mitigations, Time_of_Introduction | |||
Previous Entry Names |
|||
| Change Date | Previous Entry Name | ||
| 2010-09-27 | Insufficient Synchronization | ||
