CWE-14 编译器移除释放缓冲区的代码

admin 2022年1月7日02:54:12CWE(弱点枚举)评论19 views3780字阅读12分36秒阅读模式

CWE-14 编译器移除释放缓冲区的代码

Compiler Removal of Code to Clear Buffers

结构: Simple

Abstraction: Variant

状态: Draft

被利用可能性: unkown

基本描述

Sensitive memory is cleared according to the source code, but compiler optimizations leave the memory untouched when it is not read from again, aka "dead store removal."

扩展描述

This compiler optimization error occurs when:

相关缺陷

  • cwe_Nature: ChildOf cwe_CWE_ID: 733 cwe_View_ID: 699 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 733 cwe_View_ID: 1000 cwe_Ordinal: Primary

适用平台

Language: [{'cwe_Name': 'C', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'C++', 'cwe_Prevalence': 'Undetermined'}]

常见的影响

范围 影响 注释
['Confidentiality', 'Access Control'] ['Read Memory', 'Bypass Protection Mechanism'] This weakness will allow data that has not been cleared from memory to be read. If this data contains sensitive password information, then an attacker can read the password and use the information to bypass protection mechanisms.

检测方法

Black Box

This specific weakness is impossible to detect using black box methods. While an analyst could examine memory to see that it has not been scrubbed, an analysis of the executable would not be successful. This is because the compiler has already removed the relevant code. Only the source code shows whether the programmer intended to clear the memory or not, so this weakness is indistinguishable from others.

White Box

This weakness is only detectable using white box methods (see black box detection factor). Careful analysis is required to determine if the code is likely to be removed by the compiler.

可能的缓解方案

Implementation

策略:

Store the sensitive data in a "volatile" memory location if available.

Build and Compilation

策略:

If possible, configure your compiler so that it does not remove dead stores.

Architecture and Design

策略:

Where possible, encrypt sensitive data that are used by a software system.

示例代码

The following code reads a password from the user, uses the password to connect to a back-end mainframe and then attempts to scrub the password from memory using memset().

bad C

void GetData(char *MFAddr) {

char pwd[64];
if (GetPasswordFromUser(pwd, sizeof(pwd))) {


if (ConnectToMainframe(MFAddr, pwd)) {


// Interaction with mainframe

}

}
memset(pwd, 0, sizeof(pwd));

}

The code in the example will behave correctly if it is executed verbatim, but if the code is compiled using an optimizing compiler, such as Microsoft Visual C++ .NET or GCC 3.x, then the call to memset() will be removed as a dead store because the buffer pwd is not used after its value is overwritten [18]. Because the buffer pwd contains a sensitive value, the application may be vulnerable to attack if the data are left memory resident. If attackers are able to access the correct region of memory, they may use the recovered password to gain control of the system.

It is common practice to overwrite sensitive data manipulated in memory, such as passwords or cryptographic keys, in order to prevent attackers from learning system secrets. However, with the advent of optimizing compilers, programs do not always behave as their source code alone would suggest. In the example, the compiler interprets the call to memset() as dead code because the memory being written to is not subsequently used, despite the fact that there is clearly a security motivation for the operation to occur. The problem here is that many compilers, and in fact many programming languages, do not take this and other security concerns into consideration in their efforts to improve efficiency.

Attackers typically exploit this type of vulnerability by using a core dump or runtime mechanism to access the memory used by a particular application and recover the secret information. Once an attacker has access to the secret information, it is relatively straightforward to further exploit the system and possibly compromise other resources with which the application interacts.

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
7 Pernicious Kingdoms Insecure Compiler Optimization
PLOVER Sensitive memory uncleared by compiler optimization
OWASP Top Ten 2004 A8 CWE More Specific Insecure Storage
CERT C Secure Coding MSC06-C Be aware of compiler optimization when dealing with sensitive data
Software Fault Patterns SFP23 Exposed Data

引用

文章来源于互联网:scap中文网

特别标注: 本站(CN-SEC.COM)所有文章仅供技术研究,若将其信息做其他用途,由用户承担全部法律及连带责任,本站不承担任何法律及连带责任,请遵守中华人民共和国安全法.
  • 我的微信
  • 微信扫一扫
  • weinxin
  • 我的微信公众号
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年1月7日02:54:12
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                  CWE-14 编译器移除释放缓冲区的代码 http://cn-sec.com/archives/612682.html

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: