# VNX-432: Dangerous Signal Handler not Disabled During Sensitive Operations

Reports SA_NODEFER on a C/C++ sigaction whose handler does non-reentrant work (free, malloc, printf, syslog, exit, ...).

| Field | Value |
|---|---|
| Rule ID | `VNX-432` |
| Severity | Low |
| SARIF level | `note` |
| Kind | `sast` |
| Languages | C, C++ |
| CWE | [CWE-432](https://cwe.mitre.org/data/definitions/432.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:L/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:L/DI:H/EX:L/EC:N/P:L` |
| Tags | `dangerous-signal` `signal-handler` `cwe-432` |
| Source | [`internal/sast/rules/vnx-432.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-432.rego) |

## Overview

VNX-432 maps to [CWE-432: Dangerous Signal Handler not Disabled During Sensitive Operations](https://cwe.mitre.org/data/definitions/432.html). By default the kernel blocks a signal while its own handler runs, so the handler cannot be re-entered by the same signal. `SA_NODEFER` (and the old Linux spelling `SA_NOMASK`) switches that off. If the handler does non-reentrant work, a second delivery re-enters it half way through: a global freed twice, a stdio buffer or a lock left half updated.

## What gets flagged

The line that puts `SA_NODEFER`/`SA_NOMASK` into a `struct sigaction`'s `sa_flags` (`sa.sa_flags = ...`, `sa.sa_flags |= ...`, or a designated initialiser `{ .sa_flags = SA_NODEFER }`), when:

- the same struct's `sa_handler`/`sa_sigaction` is a function defined in the same file whose body calls something that is not async-signal-safe (`free`, `malloc`, the `printf` family, `syslog`, `exit`, `strtok`, `localtime`, `strerror`, `longjmp`, `pthread_mutex_lock`, `system`, `new`/`delete`, `std::cout`/`std::cerr`, ...), and
- the struct is passed to `sigaction()` for at least one asynchronous signal within thirty lines.

```c
static void on_hup(int sig)
{
    syslog(LOG_NOTICE, "reloading on signal %d", sig);
    free(config_buf);
}

sa.sa_handler = on_hup;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_NODEFER | SA_RESTART;   // FLAGGED
sigaction(SIGHUP, &sa, NULL);
```

## What is not flagged

- `SA_NODEFER` together with `SA_RESETHAND`: the second delivery takes the default action instead of re-entering the handler.
- Handlers installed only for synchronous fault signals (`SIGSEGV`, `SIGBUS`, `SIGFPE`, `SIGILL`, `SIGABRT`, `SIGTRAP`, `SIGSYS`), the usual crash-reporter design.
- Handlers that only set a `volatile sig_atomic_t` flag or call `write`/`_exit`, handlers defined in another file, `SIG_IGN`/`SIG_DFL`, comments and strings.

One handler installed for two or more signals with no mask is reported by VNX-831, and each non-async-signal-safe call inside a handler is reported by VNX-828. This rule reports only the flag that disables the handler's blocking of its own signal. A handler that writes an unprotected global is VNX-364.

## Remediation

1. Remove `SA_NODEFER` so the signal stays blocked while its handler runs, or add `SA_RESETHAND` if the handler is meant to run only once.
2. Fill `sa_mask` (`sigfillset(&sa.sa_mask)`) to block other signals as well.
3. Keep handlers minimal: set a `volatile sig_atomic_t` flag and do the work in the main loop.

## References

- [CWE-432](https://cwe.mitre.org/data/definitions/432.html)
- [sigaction(2): SA_NODEFER](https://man7.org/linux/man-pages/man2/sigaction.2.html)
- [signal-safety(7)](https://man7.org/linux/man-pages/man7/signal-safety.7.html)

## Suppressing this rule

Put a `nosec` comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file's language (`#`, `//`, `--` or `;`):

```text
# nosec vnx-432
// nosec vnx-432
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-432 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
