CWE-479 信号处理例程中使用不可再入的函数

admin 2021年12月16日15:50:17评论73 views字数 3386阅读11分17秒阅读模式

CWE-479 信号处理例程中使用不可再入的函数

Signal Handler Use of a Non-reentrant Function

结构: Simple

Abstraction: Variant

状态: Draft

被利用可能性: Low

基本描述

The program defines a signal handler that calls a non-reentrant function.

扩展描述

Non-reentrant functions are functions that cannot safely be called, interrupted, and then recalled before the first call has finished without resulting in memory corruption. This can lead to an unexpected system state an unpredictable results with a variety of potential consequences depending on context, including denial of service and code execution.

Many functions are not reentrant, but some of them can result in the corruption of memory if they are used in a signal handler. The function call syslog() is an example of this. In order to perform its functionality, it allocates a small amount of memory as "scratch space." If syslog() is suspended by a signal call and the signal handler calls syslog(), the memory used by both of these functions enters an undefined, and possibly, exploitable state. Implementations of malloc() and free() manage metadata in global structures in order to track which memory is allocated versus which memory is available, but they are non-reentrant. Simultaneous calls to these functions can cause corruption of the metadata.

相关缺陷

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

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

  • cwe_Nature: ChildOf cwe_CWE_ID: 663 cwe_View_ID: 1000

  • cwe_Nature: ChildOf cwe_CWE_ID: 663 cwe_View_ID: 699

  • cwe_Nature: CanPrecede cwe_CWE_ID: 123 cwe_View_ID: 1000

适用平台

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

常见的影响

范围 影响 注释
['Integrity', 'Confidentiality', 'Availability'] Execute Unauthorized Code or Commands It may be possible to execute arbitrary code through the use of a write-what-where condition.
Integrity Modify Application Data Signal race conditions often result in data corruption.

可能的缓解方案

Requirements

策略:

Require languages or libraries that provide reentrant functionality, or otherwise make it easier to avoid this weakness.

Architecture and Design

策略:

Design signal handlers to only set flags rather than perform complex functionality.

Implementation

策略:

Ensure that non-reentrant functions are not found in signal handlers.

Implementation

策略:

Use sanity checks to reduce the timing window for exploitation of race conditions. This is only a partial solution, since many attacks might fail, but other attacks still might work within the narrower window, even accidentally.

示例代码

In this example, a signal handler uses syslog() to log a message:

bad

char message;
void sh(int dummy) {

syslog(LOG_NOTICE,"%sn",message);
sleep(10);
exit(0);

}
int main(int argc,char
argv[]) {

...
signal(SIGHUP,sh);
signal(SIGTERM,sh);
sleep(10);
exit(0);

}

If the execution of the first call to the signal handler is suspended after invoking syslog(), and the signal handler is called a second time, the memory allocated by syslog() enters an undefined, and possibly, exploitable state.

分析过的案例

标识 说明 链接
CVE-2005-0893 signal handler calls function that ultimately uses malloc() https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-0893
CVE-2004-2259 SIGCHLD signal to FTP server can cause crash under heavy load while executing non-reentrant functions like malloc/free. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-2259

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
CLASP Unsafe function call from a signal handler
CERT C Secure Coding SIG30-C Exact Call only asynchronous-safe functions within signal handlers
CERT C Secure Coding SIG34-C Do not call signal() from within interruptible signal handlers
The CERT Oracle Secure Coding Standard for Java (2011) EXP01-J Never dereference null pointers
Software Fault Patterns SFP3 Use of an improper API

引用

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

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年12月16日15:50:17
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   CWE-479 信号处理例程中使用不可再入的函数http://cn-sec.com/archives/613251.html

发表评论

匿名网友 填写信息