Improperly Controlled Sequential Memory Allocation

Incomplete Base
Structure: Simple
Description

The product manages a group of objects or resources and performs a separate memory allocation for each object, but it does not properly limit the total amount of memory that is consumed by all of the combined objects.

Extended Description

While the product might limit the amount of memory that is allocated in a single operation for a single object (such as a malloc of an array), if an attacker can cause multiple objects to be allocated in separate operations, then this might cause higher total memory consumption than the developer intended, leading to a denial of service.

Common Consequences 1
Scope: Availability

Impact: DoS: Resource Consumption (Memory)

Not controlling memory allocation can result in a request for too much system memory, possibly leading to a crash of the application due to out-of-memory conditions, or the consumption of a large amount of memory on the system.

Potential Mitigations 2
Phase: Implementation
Ensure multiple allocations of the same kind of object are properly tracked - possibly across multiple sessions, requests, or messages. Define an appropriate strategy for handling requests that exceed the limit, and consider supporting a configuration option so that the administrator can extend the amount of memory to be used if necessary.
Phase: Operation
Run the program using system-provided resource limits for memory. This might still cause the program to crash or exit, but the impact to the rest of the system will be minimized.
Demonstrative Examples 1
This example contains a small allocation of stack memory. When the program was first constructed, the number of times this memory was allocated was probably inconsequential and presented no problem. Over time, as the number of objects in the database grow, the number of allocations will grow - eventually consuming the available stack, i.e. "stack exhaustion." An attacker who is able to add elements to the database could cause stack exhaustion more rapidly than assumed by the developer.

Code Example:

Bad
C

// Gets the size from the number of objects in a database, which over time can conceivably get very large* int end_limit = get_nmbr_obj_from_db(); int i; int *base = NULL; int *p =base; for (i = 0; i < end_limit; i++) {

c
c
Since this uses alloca(), it allocates memory directly on the stack. If end_limit is large enough, then the stack can be entirely consumed.
Observed Examples 3
CVE-2020-36049JavaScript-based packet decoder uses concatenation of many small strings, causing out-of-memory (OOM) condition
CVE-2019-20176Product allocates a new buffer on the stack for each file in a directory, allowing stack exhaustion
CVE-2013-1591Chain: an integer overflow (Integer Overflow or Wraparound) in the image size calculation causes an infinite loop (Loop with Unreachable Exit Condition ('Infinite Loop')) which sequentially allocates buffers without limits (Improperly Controlled Sequential Memory Allocation) until the stack is full.
Applicable Platforms
Languages:
C : UndeterminedC++ : UndeterminedNot Language-Specific : Undetermined
Modes of Introduction
Implementation
Alternate Terms

Stack Exhaustion

When a weakness allocates excessive memory on the stack, it is often described as "stack exhaustion," which is a technical impact of the weakness. This technical impact is often encountered as a consequence of Memory Allocation with Excessive Size Value and/or Improperly Controlled Sequential Memory Allocation.