Class · High

CWE-400: Uncontrolled Resource Consumption

The product does not properly control the allocation and maintenance of a limited resource.

CWE-400 · Class Level ·17 CVEs ·4 Mitigations

Description

The product does not properly control the allocation and maintenance of a limited resource.

Potential Impact

Availability

DoS: Crash, Exit, or Restart, DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), DoS: Resource Consumption (Other)

Access Control, Other

Bypass Protection Mechanism, Other

Demonstrative Examples

The following example demonstrates the weakness.
Bad
class Worker implements Executor {
                        ...public void execute(Runnable r) {
                              
                                 try {...}catch (InterruptedException ie) {
                                    
                                       
                                       // postpone response
                                       Thread.currentThread().interrupt();
                                 }
                           }
                           public Worker(Channel ch, int nworkers) {...}
                           protected void activate() {
                              
                                 Runnable loop = new Runnable() {
                                    
                                       public void run() {
                                          
                                             try {for (;;) {Runnable r = ...;r.run();}}catch (InterruptedException ie) {...}
                                       }
                                 };new Thread(loop).start();
                           }
                     }
There are no limits to runnables. Potentially an attacker could cause resource problems very quickly.
This code allocates a socket and forks each time it receives a new connection.
Bad
sock=socket(AF_INET, SOCK_STREAM, 0);while (1) {newsock=accept(sock, ...);printf("A connection has been accepted\n");pid = fork();}
The program does not track how many connections have been made, and it does not limit the number of connections. Because forking is a relatively expensive operation, an attacker would be able to cause the system to run out of CPU, processes, or memory by making a large number of connections. Alternatively, an attacker could consume all available connections, preventing others from accessing the system remotely.
In the following example a server socket connection is used to accept a request to store data on the local file system using a specified filename. The method openSocketConnection establishes a server socket to accept requests from a client. When a client establishes a connection to this service the getNextMessage method is first used to retrieve from the socket the name of the file to store the data, the openFileToWrite method will validate the filename and open a file to write to on the local file system. The getNextMessage is then used within a while loop to continuously read data from the socket and output the data to the file until there is no longer any data from the socket.
Bad
int writeDataFromSocketToFile(char *host, int port){
                        
                           char filename[FILENAME_SIZE];char buffer[BUFFER_SIZE];int socket = openSocketConnection(host, port);
                           if (socket < 0) {printf("Unable to open socket connection");return(FAIL);}if (getNextMessage(socket, filename, FILENAME_SIZE) > 0) {
                              if (openFileToWrite(filename) > 0) {
                                    while (getNextMessage(socket, buffer, BUFFER_SIZE) > 0){if (!(writeToFile(buffer) > 0))break;
                                       }
                                 }closeFile();
                           }closeSocket(socket);
                     }
This example creates a situation where data can be dumped to a file on the local file system without any limits on the size of the file. This could potentially exhaust file or disk resources and/or limit other clients' ability to access the service.
In the following example, the processMessage method receives a two dimensional character array containing the message to be processed. The two-dimensional character array contains the length of the message in the first character array and the message body in the second character array. The getMessageLength method retrieves the integer value of the length from the first character array. After validating that the message length is greater than zero, the body character array pointer points to the start of the second character array of the two-dimensional character array and memory is allocated for the new body character array.
Bad
/* process message accepts a two-dimensional character array of the form [length][body] containing the message to be processed */
                     int processMessage(char **message){
                        char *body;
                           int length = getMessageLength(message[0]);
                           if (length > 0) {body = &message[1][0];processMessageBody(body);return(SUCCESS);}else {printf("Unable to process message; invalid message length");return(FAIL);}
                     }
This example creates a situation where the length of the body character array can be very large and will consume excessive memory, exhausting system resources. This can be avoided by restricting the length of the second character array with a maximum length check
Also, consider changing the type from 'int' to 'unsigned int', so that you are always guaranteed that the number is positive. This might not be possible if the protocol specifically requires allowing negative values, or if you cannot control the return value from getMessageLength(), but it could simplify the check to ensure the input is positive, and eliminate other errors such as signed-to-unsigned conversion errors (CWE-195) that may occur elsewhere in the code.
Good
unsigned int length = getMessageLength(message[0]);if ((length > 0) && (length < MAX_LENGTH)) {...}

Mitigations & Prevention

Architecture and Design

Design throttling mechanisms into the system architecture. The best protection is to limit the amount of resources that an unauthorized user can cause to be expended. A strong authentication and access control model will help prevent such attacks from occurring in the first place. The login application should be protected against DoS attacks as much as possible. Limiting the database access, perhaps by caching result sets, can help minimize the resources expended. To further limit the potential

Architecture and Design

Mitigation of resource exhaustion attacks requires that the target system either: The first of these solutions is an issue in itself though, since it may allow attackers to prevent the use of the system by a particular valid user. If the attacker impersonates the valid user, they may be able to prevent the user from accessing the server in question. The second solution is simply difficult to effectively inst

Architecture and Design

Ensure that protocols have specific limits of scale placed on them.

Implementation

Ensure that all failures in resource allocation place the system into a safe posture.

Detection Methods

  • Automated Static Analysis Limited — Automated static analysis typically has limited utility in recognizing resource exhaustion problems, except for program-independent system resources such as files, sockets, and processes. For system resources, automated static analysis may be able to detect circumstances in which resources are not r
  • Automated Dynamic Analysis Moderate — Certain automated dynamic analysis techniques may be effective in spotting resource exhaustion problems, especially with resources such as processes, memory, and connections. The technique may involve generating a large number of requests to the product within a short time frame.
  • Fuzzing Opportunistic — While fuzzing is typically geared toward finding low-level implementation bugs, it can inadvertently find resource exhaustion problems. This can occur when the fuzzer generates a large number of test cases but does not restart the targeted product in between test cases. If an individual test case pr

Real-World CVE Examples

CVE IDDescription
CVE-2019-19911Chain: Python library does not limit the resources used to process images that specify a very large number of bands (CWE-1284), leading to excessive memory consumption (CWE-789) or an integer overflow
CVE-2020-7218Go-based workload orchestrator does not limit resource usage with unauthenticated connections, allowing a DoS by flooding the service
CVE-2020-3566Resource exhaustion in distributed OS because of "insufficient" IGMP queue management, as exploited in the wild per CISA KEV.
CVE-2009-2874Product allows attackers to cause a crash via a large number of connections.
CVE-2009-1928Malformed request triggers uncontrolled recursion, leading to stack exhaustion.
CVE-2009-2858Chain: memory leak (CWE-404) leads to resource exhaustion.
CVE-2009-2726Driver does not use a maximum width when invoking sscanf style functions, causing stack consumption.
CVE-2009-2540Large integer value for a length property in an object causes a large amount of memory allocation.
CVE-2009-2299Web application firewall consumes excessive memory when an HTTP request contains a large Content-Length value but no POST data.
CVE-2009-2054Product allows exhaustion of file descriptors when processing a large number of TCP packets.
CVE-2008-5180Communication product allows memory consumption with a large number of SIP requests, which cause many sessions to be created.
CVE-2008-2121TCP implementation allows attackers to consume CPU and prevent new connections using a TCP SYN flood attack.
CVE-2008-2122Port scan triggers CPU consumption with processes that attempt to read data from closed sockets.
CVE-2008-1700Product allows attackers to cause a denial of service via a large number of directives, each of which opens a separate window.
CVE-2007-4103Product allows resource exhaustion via a large number of calls that do not complete a 3-way handshake.

Showing 15 of 17 observed examples.

Taxonomy Mappings

  • CLASP: — Resource exhaustion (file descriptor, disk space, sockets, ...)
  • OWASP Top Ten 2004: A9 — Denial of Service
  • WASC: 10 — Denial of Service
  • WASC: 41 — XML Attribute Blowup
  • The CERT Oracle Secure Coding Standard for Java (2011): SER12-J — Avoid memory and resource leaks during serialization
  • The CERT Oracle Secure Coding Standard for Java (2011): MSC05-J — Do not exhaust heap space
  • Software Fault Patterns: SFP13 — Unrestricted Consumption
  • ISA/IEC 62443: Part 3-3 — Req SR 7.1
  • ISA/IEC 62443: Part 3-3 — Req SR 7.2
  • ISA/IEC 62443: Part 4-1 — Req SI-1
  • ISA/IEC 62443: Part 4-1 — Req SVV-3
  • ISA/IEC 62443: Part 4-2 — Req CR 7.1
  • ISA/IEC 62443: Part 4-2 — Req CR 7.2

Frequently Asked Questions

What is CWE-400?

CWE-400 (Uncontrolled Resource Consumption) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Class-level weakness. The product does not properly control the allocation and maintenance of a limited resource.

How can CWE-400 be exploited?

Attackers can exploit CWE-400 (Uncontrolled Resource Consumption) to dos: crash, exit, or restart, dos: resource consumption (cpu), dos: resource consumption (memory), dos: resource consumption (other). This weakness is typically introduced during the Operation, System Configuration, Architecture and Design, Implementation phase of software development.

How do I prevent CWE-400?

Key mitigations include: Design throttling mechanisms into the system architecture. The best protection is to limit the amount of resources that an unauthorized user can cause to be expended. A strong authentication and acces

What is the severity of CWE-400?

CWE-400 is classified as a Class-level weakness (High abstraction). It has been observed in 17 real-world CVEs.