CWE
Home > CWE List > CWE-120 Individual Dictionary Definition (Draft 9)   View the CWE List

CWE-120 Individual Dictionary Definition (Draft 9)

Unbounded Transfer ('Classic Buffer Overflow')
Compound Element ID
Status: Incomplete

120 (Compound Element Base: Composite)

Description

Summary

A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold or when a program attempts to put data in a memory area past a buffer. In this case, a buffer is a sequential section of memory allocated to contain anything from a character string to an array of integers.

Alternate Terms

Some prominent vendors and researchers use the term "buffer overrun," but most people use "buffer overflow."

Many issues that are now called "buffer overflows" are substantively different than the "classic" overflow, including entirely different bug types that rely on overflow exploit techniques, such as integer signedness errors, integer overflows, and format string bugs. This imprecise terminology can make it difficult to determine which variant is being reported.

Functional Area

Memory Management

Likelihood of Exploit

High to Very High

Weakness Ordinality

Resultant (Weakness is typically related to the presence of some other weaknesses)

Primary (Weakness exists independent of other weaknesses)

Causal Nature

Explicit (This is an explicit weakness resulting from behavior of the developer)

Affected Resource

Memory

Common Consequences

Availability: Buffer overflows generally lead to crashes. Other attacks leading to lack of availability are possible, including putting the program into an infinite loop.

Access control (instruction processing): Buffer overflows often can be used to execute arbitrary code, which is usually outside the scope of a program's implicit security policy.

Other: When the consequence is arbitrary code execution, this can often be used to subvert any other security service.

Potential Mitigations

Pre-design: Use a language or compiler that performs automatic bounds checking.

Design: Use an abstraction library to abstract away risky APIs. Not a complete solution.

Design: Use the <strsafe.h> library. This library has buffer overflow safe functions that will help with the detection of buffer overflows.

Pre-design through Build: Compiler-based canary mechanisms such as StackGuard, ProPolice and the Microsoft Visual Studio /GS flag. Unless this provides automatic bounds checking, it is not a complete solution.

Implementation: Programmers should adhere to the following rules when allocating and managing their applications memory: Double check that your buffer is as large as you specify. When using functions that accept a number of bytes to copy, such as strncpy(), be aware that if the destination buffer size is equal to the source buffer size, it may not NULL-terminate the string. Check buffer boundaries if calling this function in a loop and make sure you are not in danger of writing past the allocated space. Truncate all input strings to a reasonable length before passing them to the copy and concatenation functions

Operational: Use OS-level preventative functionality. Not a complete solution.

Observed Examples
ReferenceDescription
CVE-2000-1094buffer overflow using command with long argument
CVE-1999-0046buffer overflow in local program using long environment variable
CVE-2002-1337buffer overflow in comment characters, when product increments a counter for a ">" but does not decrement for "<"
CVE-2003-0595 - By replacing a valid cookie value with an extremely long string of characters, an attacker may overflow the application's buffers.
CVE-2001-0191 - By replacing a valid cookie value with an extremely long string of characters, an attacker may overflow the application's buffers.
Context Notes

At the programmer level, stack-based and heap-based overflows do not differ significantly, so they are not distinguished here. Obviously, from the exploit perspective using shellcode, they can be quite different.

Buffer overflows are one of the best known types of security problem. The best solution is enforced run-time bounds checking of array access, but many C/C++ programmers assume this is too costly or do not have the technology available to them. Even this problem only addresses failures in access control -- as an out-of-bounds access is still an exception condition and can lead to an availability problem if not addressed. Some platforms are introducing mitigating technologies at the compiler or OS level. All such technologies to date address only a subset of buffer overflow problems and rarely provide complete protection against even that subset. It is more common to make the workload of an attacker much higher -- for example, by leaving the attacker to guess an unknown value that changes every program execution.

Relationships
NatureTypeIDName
ChildOfWeakness ClassWeakness ClassWeakness Class119Failure to Constrain Operations within the Bounds of an Allocated Memory Buffer
RequiresWeakness ClassWeakness ClassWeakness Class227Failure to Fulfill API Contract (aka 'API Abuse')
RequiresWeakness ClassWeakness ClassWeakness Class242Use of Inherently Dangerous Function
CanPrecedeWeakness BaseWeakness BaseWeakness Base123Write-what-where Condition
ChildOfCategoryCategory633Weaknesses that Affect Memory
CanPrecedeCompound Element: ChainCompound Element: Chain680Integer Overflow to Buffer Overflow
ParentOfWeakness VariantWeakness VariantWeakness Variant121Stack-based Buffer Overflow
ParentOfWeakness VariantWeakness VariantWeakness Variant122Heap-based Buffer Overflow
PeerOfWeakness BaseWeakness BaseWeakness Base124Boundary Beginning Violation ('Buffer Underwrite')
PeerOfWeakness BaseWeakness BaseWeakness Base132Miscalculated Null Termination
CanFollowWeakness BaseWeakness BaseWeakness Base170Improper Null Termination
CanFollowWeakness BaseWeakness BaseWeakness Base190Integer Overflow (Wrap or Wraparound)
CanAlsoBeWeakness VariantWeakness VariantWeakness Variant196Unsigned to Signed Conversion Error
CanAlsoBeWeakness BaseWeakness BaseWeakness Base231Failure to Handle Extra Value
ParentOfWeakness VariantWeakness VariantWeakness Variant249Often Misused: Path Manipulation
CanFollowWeakness BaseWeakness BaseWeakness Base416Use After Free
CanFollowWeakness BaseWeakness BaseWeakness Base456Missing Initialization
Source Taxonomies

PLOVER - Unbounded Transfer ('classic overflow')

7 Pernicious Kingdoms - Buffer Overflow

CLASP - Buffer overflow

Applicable Platforms

C

C++

Time of Introduction

Implementation

Related Attack Patterns
CAPEC-IDAttack Pattern Name
100Overflow Buffers
10Buffer Overflow via Environment Variables
14Client-side Injection-induced Buffer Overflow
42MIME Conversion
24Filter Failure through Buffer Overflow
8Buffer Overflow in an API Call
9Buffer Overflow in Local Command-Line Utilities
45Buffer Overflow via Symbolic Links
46Overflow Variables and Tags
47Buffer Overflow via Parameter Expansion
92Forced Integer Overflow
67String Format Overflow in syslog()
White Box Definition


A weakness where the code path includes a Buffer Write Operation such that:
1.        the expected size of the buffer is greater than the actual size of the buffer where expected size is equal to the sum of the size of the data item and the position in the buffer

Where Buffer Write Operation is a statement that writes a data item of a certain size into a buffer at a certain position and at a certain index

Page Last Updated: April 21, 2008