CWE-121: Stack-based Buffer Overflow
CWE版本: 4.18
更新日期: 2025-09-09
弱点描述
A stack-based buffer overflow condition is a condition where the buffer being overwritten is allocated on the stack (i.e., is a local variable or, rarely, a parameter to a function).
常见后果
影响范围: Availability
技术影响: Modify Memory 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
技术影响: Modify Memory Execute Unauthorized Code or Commands Bypass Protection Mechanism
说明: Buffer overflows often can be used to execute arbitrary code, which is usually outside the scope of a program's implicit security policy.
影响范围: Integrity Confidentiality Availability Access Control Other
技术影响: Modify Memory 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.
潜在缓解措施
阶段: Operation Build and Compilation
策略: Environment Hardening
有效性: Defense in Depth
阶段: Architecture and Design
描述: Use an abstraction library to abstract away risky APIs. Not a complete solution.
阶段: Implementation
描述: Implement and perform bounds checking on input.
阶段: Implementation
描述: Do not use dangerous functions such as gets. Use safer, equivalent functions which check for boundary errors.
阶段: Operation Build and Compilation
策略: Environment Hardening
有效性: 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
方法: Automated Static Analysis
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
有效性: High
观察示例
参考: CVE-2021-35395
Stack-based buffer overflows in SFK for wifi chipset used for IoT/embedded devices, as exploited in the wild per CISA KEV.
引入模式
| 阶段 | 说明 |
|---|---|
| Implementation | - |
适用平台
编程语言
分类映射
| 分类名称 | 条目ID | 条目名称 | 映射适配度 |
|---|---|---|---|
| CLASP | - | Stack overflow | - |
| Software Fault Patterns | SFP8 | Faulty Buffer Access | - |
| CERT C Secure Coding | ARR38-C | Guarantee that library functions do not form invalid pointers | Imprecise |
| CERT C Secure Coding | STR31-C | Guarantee that storage for strings has sufficient space for character data and the null terminator | CWE More Specific |