CWE-122: Heap-based Buffer Overflow
CWE版本: 4.18
更新日期: 2025-09-09
弱点描述
A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().
常见后果
影响范围: Availability
技术影响: DoS: Crash, Exit, or Restart DoS: Resource Consumption (CPU) DoS: Resource Consumption (Memory)
说明: Buffer overflows generally lead to crashes. Other attacks leading to lack of availability are possible, including putting the program into an infinite loop.
影响范围: Integrity Confidentiality Availability Access Control
技术影响: Execute Unauthorized Code or Commands Bypass Protection Mechanism Modify Memory
说明: Buffer overflows often can be used to execute arbitrary code, which is usually outside the scope of a program's implicit security policy. Besides important user data, heap-based overflows can be used to overwrite function pointers that may be living in memory, pointing it to the attacker's code. Even in applications that do not explicitly use function pointers, the run-time will usually leave many in memory. For example, object methods in C++ are generally implemented using function pointers. Even in C programs, there is often a global offset table used by the underlying runtime.
影响范围: Integrity Confidentiality Availability Access Control Other
技术影响: Execute Unauthorized Code or Commands Bypass Protection Mechanism Other
说明: When the consequence is arbitrary code execution, this can often be used to subvert any other security service.
潜在缓解措施
描述: Pre-design: Use a language or compiler that performs automatic bounds checking.
阶段: Architecture and Design
描述: Use an abstraction library to abstract away risky APIs. Not a complete solution.
阶段: Operation Build and Compilation
策略: Environment Hardening
有效性: Defense in Depth
阶段: Operation Build and Compilation
策略: Environment Hardening
有效性: Defense in Depth
阶段: Implementation
描述: Implement and perform bounds checking on input.
阶段: Implementation
策略: Libraries or Frameworks
描述: Do not use dangerous functions such as gets. Look for their safe equivalent, which checks for the boundary.
阶段: Operation
描述: Use OS-level preventative functionality. This is not a complete solution, but it provides some defense in depth.
检测方法
方法: Fuzzing
Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.
有效性: High
观察示例
参考: CVE-2021-43537
Chain: in a web browser, an unsigned 64-bit integer is forcibly cast to a 32-bit integer (CWE-681) and potentially leading to an integer overflow (CWE-190). If an integer overflow occurs, this can cause heap memory corruption (CWE-122)
参考: CVE-2007-4268
Chain: integer signedness error (CWE-195) passes signed comparison, leading to heap overflow (CWE-122)
参考: CVE-2009-2523
Chain: product does not handle when an input string is not NULL terminated (CWE-170), leading to buffer over-read (CWE-125) or heap-based buffer overflow (CWE-122).
参考: CVE-2021-29529
Chain: machine-learning product can have a heap-based buffer overflow (CWE-122) when some integer-oriented bounds are calculated by using ceiling() and floor() on floating point values (CWE-1339)
参考: CVE-2010-1866
Chain: integer overflow (CWE-190) causes a negative signed value, which later bypasses a maximum-only check (CWE-839), leading to heap-based buffer overflow (CWE-122).
引入模式
| 阶段 | 说明 |
|---|---|
| Implementation | - |
适用平台
编程语言
分类映射
| 分类名称 | 条目ID | 条目名称 | 映射适配度 |
|---|---|---|---|
| CLASP | - | Heap overflow | - |
| Software Fault Patterns | SFP8 | Faulty Buffer Access | - |
| CERT C Secure Coding | STR31-C | Guarantee that storage for strings has sufficient space for character data and the null terminator | CWE More Specific |
| ISA/IEC 62443 | Part 4-2 | Req CR 3.5 | - |
| ISA/IEC 62443 | Part 3-3 | Req SR 3.5 | - |
| ISA/IEC 62443 | Part 4-1 | Req SI-1 | - |
| ISA/IEC 62443 | Part 4-1 | Req SI-2 | - |
| ISA/IEC 62443 | Part 4-1 | Req SVV-1 | - |
| ISA/IEC 62443 | Part 4-1 | Req SVV-3 | - |