Description
The product defines a function that is used as a handler for more than one signal.
While sometimes intentional and safe, when the same function is used to handle multiple signals, a race condition could occur if the function uses any state outside of its local declaration, such as global variables or non-reentrant functions, or has any side effects. An attacker could send one signal that invokes the handler function; in many OSes, this will typically prevent the same signal from invoking the handler again, at least until the handler function has completed execution. However, the attacker could then send a different signal that is associated with the same handler function. This could interrupt the original handler function while it is still executing. If there is shared state, then the state could be corrupted. This can lead to a variety of potential consequences depending on context, including denial of service and code execution. Another rarely-explored possibility arises when the signal handler is only designed to be executed once (if at all). By sending multiple signals, an attacker could invoke the function more than once. This may generate extra, unintended side effects. A race condition might not even be necessary; the attacker could send one signal, wait until it is handled, then send the other signal.
Potential Impact
Availability, Integrity, Confidentiality, Access Control, Other
DoS: Crash, Exit, or Restart, Execute Unauthorized Code or Commands, Read Application Data, Gain Privileges or Assume Identity, Bypass Protection Mechanism, Varies by Context
Demonstrative Examples
void handler (int sigNum) {...}
int main (int argc, char* argv[]) {signal(SIGUSR1, handler)signal(SIGUSR2, handler)}char *logMessage;
void handler (int sigNum) {
syslog(LOG_NOTICE, "%s\n", logMessage);free(logMessage);
/* artificially increase the size of the timing window to make demonstration of this weakness easier. */
sleep(10);exit(0);
}
int main (int argc, char* argv[]) {
logMessage = strdup(argv[1]);
/* Register signal handlers. */
signal(SIGHUP, handler);signal(SIGTERM, handler);
/* artificially increase the size of the timing window to make demonstration of this weakness easier. */
sleep(10);
}Related Weaknesses
Frequently Asked Questions
What is CWE-831?
CWE-831 (Signal Handler Function Associated with Multiple Signals) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Variant-level weakness. The product defines a function that is used as a handler for more than one signal.
How can CWE-831 be exploited?
Attackers can exploit CWE-831 (Signal Handler Function Associated with Multiple Signals) to dos: crash, exit, or restart, execute unauthorized code or commands, read application data, gain privileges or assume identity, bypass protection mechanism, varies by context. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-831?
Follow secure coding practices, conduct code reviews, and use automated security testing tools (SAST/DAST) to detect this weakness early in the development lifecycle.
What is the severity of CWE-831?
CWE-831 is classified as a Variant-level weakness (Low-Medium abstraction). Its actual severity depends on the specific context and how the weakness manifests in your application.