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.




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.



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



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:


char message;
void sh(int dummy) {
int main(int argc,char
argv[]) {
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()
CVE-2004-2259 SIGCHLD signal to FTP server can cause crash under heavy load while executing non-reentrant functions like malloc/free.


映射的分类名 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