Unrestricted Externally Accessible Lock

The product properly checks for the existence of a lock, but the lock can be externally controlled or influenced by an actor that is outside of the intended sphere of control.


Description

This prevents the product from acting on associated resources or performing other behaviors that are controlled by the presence of the lock. Relevant locks might include an exclusive lock or mutex, or modifying a shared resource that is treated as a lock. If the lock can be held for an indefinite period of time, then the denial of service could be permanent.

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

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

See Also

Comprehensive Categorization: Concurrency

Weaknesses in this category are related to concurrency.

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.

SFP Secondary Cluster: Unrestricted Lock

This category identifies Software Fault Patterns (SFPs) within the Unrestricted Lock cluster (SFP22).

Comprehensive CWE Dictionary

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

Weaknesses Introduced During Implementation

This view (slice) lists weaknesses that can be introduced during implementation.

Weaknesses Introduced During Design

This view (slice) lists weaknesses that can be introduced during design.


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.