Missing Synchronization

The software utilizes a shared resource in a concurrent manner but does not attempt to synchronize access to the resource.


Description

If access to a shared resource is not synchronized, then the resource may not be in a state that is expected by the software. This might lead to unexpected or insecure behaviors, especially if an attacker can influence the shared resource.

Demonstrations

The following examples help to illustrate the nature of this weakness and describe methods or techniques which can be used to mitigate the risk.

Note that the examples here are by no means exhaustive and any given weakness may have many subtle varieties, each of which may require different detection methods or runtime controls.

Example One

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

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:

PARENT

child

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]

See Also

SEI CERT Oracle Secure Coding Standard for Java - Guidelines 09. Locking (LCK)

Weaknesses in this category are related to the rules and recommendations in the Locking (LCK) section of the SEI CERT Oracle Secure Coding Standard for Java.

Concurrency Issues

Weaknesses in this category are related to concurrent use of shared resources.

Comprehensive CWE Dictionary

This view (slice) covers all the elements in CWE.

Entries with Maintenance Notes

CWE entries in this view have maintenance notes. Maintenance notes are an indicator that an entry might change significantly in future versions. This view was created...

Weaknesses without Software Fault Patterns

CWE identifiers in this view are weaknesses that do not have associated Software Fault Patterns (SFPs), as covered by the CWE-888 view. As such, they represent gaps in...


Common Weakness Enumeration content on this website is copyright of The MITRE Corporation unless otherwise specified. Use of the Common Weakness Enumeration and the associated references on this website are subject to the Terms of Use as specified by The MITRE Corporation.