Description
The product 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 and 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.
Potential Impact
Integrity, Confidentiality, Availability
Execute Unauthorized Code or Commands
Integrity
Modify Memory, Modify Application Data
Demonstrative Examples
char *message;void sh(int dummy) {syslog(LOG_NOTICE,"%s\n",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.Mitigations & Prevention
Require languages or libraries that provide reentrant functionality, or otherwise make it easier to avoid this weakness.
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.
Detection Methods
- Automated Static Analysis High — 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 sea
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| 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. |
Related Weaknesses
Taxonomy Mappings
- CLASP: — Unsafe function call from a signal handler
- CERT C Secure Coding: SIG30-C — 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
Frequently Asked Questions
What is CWE-479?
CWE-479 (Signal Handler Use of a Non-reentrant Function) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Variant-level weakness. The product defines a signal handler that calls a non-reentrant function.
How can CWE-479 be exploited?
Attackers can exploit CWE-479 (Signal Handler Use of a Non-reentrant Function) to execute unauthorized code or commands. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-479?
Key mitigations include: Require languages or libraries that provide reentrant functionality, or otherwise make it easier to avoid this weakness.
What is the severity of CWE-479?
CWE-479 is classified as a Variant-level weakness (Low-Medium abstraction). It has been observed in 2 real-world CVEs.