...
Asynchronous signals may originate from malicious actors external to the process. Consequently, vulnerabilities may exist if the signal-handler-persistence behavior is inconsistent with the developer's expectations, such as when the developer expects the signal handler to persist but it does not.
...
A common approach to create persistent signal handlers is to call signal() from within the handler itself, consequently , unresetting the reset signal:
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
/* * Equivalent to signal(SIGUSR1, handler) but makes * signal persistent. */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; if (sigemptyset(&act.sa_mask) != 0) { /* Handle error */ } if (sigaction(SIGUSR1, &act, NULL) != 0) { /* Handle error */ } |
...
With the compliant solution for UNIX, no race condition occurs that can be exploited by an attacker sending a second signal. This is because a second signal sent to the handler, before the latter calls signal(signum, SIG_DFL), will only cause the handler to restart and call signal() anyway.
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
/* * Equivalent to signal(SIGUSR1, handler) but makes * signal nonpersistent . */ struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_RESETHAND; if (sigemptyset(&act.sa_mask) != 0) { /* Handle error */ } if (sigaction(SIGUSR1, &act, NULL) != 0) { /* Handle error */ } |
...
Failure to understand implementation-specific details regarding signal-handler persistence can lead to unexpected behavior.
Recommendation | Severity | Likelihood | Detectable |
|---|
Repairable | Priority | Level |
|---|---|---|
SIG01-C | Low |
Unlikely |
No |
No |
P1 | L3 |
Automated Detection
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| CodeSonar |
| BADFUNC.SIGNAL | Use of signal | ||||||
| Compass/ROSE |
Could detect possible violations by flagging any signal handler that calls |
| Helix QAC |
| C5020 | |||||||
| LDRA tool suite |
| 97 D | Partially implemented | ||||||
| Parasoft C/C++test |
|
|
|
| CERT_C-SIG01-a | The signal handling facilities of <signal.h> shall not be used | ||||||||
| PC-lint Plus |
| 586 | Assistance provided: reports use of the signal function |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
| SEI CERT C++ |
| Coding Standard | VOID SIG01-CPP. Understand implementation-specific details regarding signal handler persistence |
...
...