Ejecuta análisis estático (SAST) sobre el código buscando el patrón inseguro en el flujo de datos.
Signal Handler Function Associated with Multiple Signals
This vulnerability occurs when a single function is registered to handle multiple different operating system signals, creating potential race conditions if that function isn't carefully designed.
What is CWE-831?
Real-world CVEs caused by CWE-831
Todavía no hay CVEs públicos enlazados a esta CWE en el catálogo de MITRE.
Ruta del atacante paso a paso
- 1
This code registers the same signal handler function with two different signals.
- 2
This code registers the same signal handler function with two different signals (CWE-831). If those signals are sent to the process, the handler creates a log message (specified in the first argument to the program) and exits.
- 3
The handler function uses global state (globalVar and logMessage), and it can be called by both the SIGHUP and SIGTERM signals. An attack scenario might follow these lines:
- 4
- The program begins execution, initializes logMessage, and registers the signal handlers for SIGHUP and SIGTERM. - The program begins its "normal" functionality, which is simplified as sleep(), but could be any functionality that consumes some time. - The attacker sends SIGHUP, which invokes handler (call this "SIGHUP-handler"). - SIGHUP-handler begins to execute, calling syslog(). - syslog() calls malloc(), which is non-reentrant. malloc() begins to modify metadata to manage the heap. - The attacker then sends SIGTERM. - SIGHUP-handler is interrupted, but syslog's malloc call is still executing and has not finished modifying its metadata. - The SIGTERM handler is invoked. - SIGTERM-handler records the log message using syslog(), then frees the logMessage variable.
- 5
At this point, the state of the heap is uncertain, because malloc is still modifying the metadata for the heap; the metadata might be in an inconsistent state. The SIGTERM-handler call to free() is assuming that the metadata is inconsistent, possibly causing it to write data to the wrong location while managing the heap. The result is memory corruption, which could lead to a crash or even code execution, depending on the circumstances under which the code is running.
Vulnerable C
This code registers the same signal handler function with two different signals.
void handler (int sigNum) {
...
}
int main (int argc, char* argv[]) {
signal(SIGUSR1, handler)
signal(SIGUSR2, handler)
} Secure pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
const safe = validateAndEscape(input);
return executeWithGuards(safe);
} How to prevent CWE-831
- Architecture Use safe-by-default frameworks and APIs that prevent the unsafe pattern from being expressible.
- Implementation Validate input at trust boundaries; use allowlists, not denylists.
- Implementation Apply the principle of least privilege to credentials, file paths, and runtime permissions.
- Testing Cover this weakness in CI: SAST rules + targeted unit tests for the data flow.
- Operation Monitor logs for the runtime signals listed in the next section.
How to detect CWE-831
Ejecuta pruebas dinámicas de seguridad de aplicaciones (DAST) contra el endpoint en vivo.
Vigila los logs en tiempo de ejecución para detectar trazas de excepción inusuales, entradas malformadas o intentos de bypass de autorización.
Revisión de código: marca cualquier código nuevo que maneje entrada desde esta superficie sin usar los helpers validados del framework.
Plexicus detecta automáticamente CWE-831 y abre un PR de corrección en menos de 60 segundos.
Codex Remedium escanea cada commit, identifica esta debilidad concreta y entrega un pull request listo para revisión con el parche. Sin tickets. Sin traspasos.
Frequently asked questions
¿Qué es CWE-831?
This vulnerability occurs when a single function is registered to handle multiple different operating system signals, creating potential race conditions if that function isn't carefully designed.
¿Qué gravedad tiene CWE-831?
MITRE no ha publicado una calificación de probabilidad de explotación para esta debilidad. Trátala como de impacto medio hasta que tu modelo de amenazas demuestre lo contrario.
¿Qué lenguajes o plataformas se ven afectados por CWE-831?
MITRE no ha especificado plataformas afectadas para esta CWE — puede aplicar a la mayoría de los stacks de aplicaciones.
¿Cómo puedo prevenir CWE-831?
Use safe-by-default frameworks, validate untrusted input at trust boundaries, and apply the principle of least privilege. Cover the data-flow signature in CI with SAST.
¿Cómo detecta y corrige Plexicus CWE-831?
El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-831 en cada commit. Cuando hay coincidencia, nuestro agente Codex Remedium abre un PR de corrección con el código corregido, las pruebas y un resumen de una línea para el revisor.
¿Dónde puedo aprender más sobre CWE-831?
MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/831.html. También puedes consultar la documentación de OWASP y NIST para guías relacionadas.
Weaknesses related to CWE-831
Signal Handler Race Condition
A signal handler race condition occurs when a program's signal handling routine is vulnerable to timing issues, allowing its state to be…
Dangerous Signal Handler not Disabled During Sensitive Operations
This vulnerability occurs when a program's signal handler, which shares resources like global variables with other handlers, can be…
Signal Handler with Functionality that is not Asynchronous-Safe
This weakness occurs when a program's signal handler contains code that is not asynchronous-safe. This means the handler can be…
Further reading
- MITRE — CWE-831 oficial https://cwe.mitre.org/data/definitions/831.html
- Delivering Signals for Fun and Profit https://lcamtuf.coredump.cx/signals.txt
- Race Condition: Signal Handling https://vulncat.fortify.com/en/detail?id=desc.structural.cpp.race_condition_signal_handling#:~:text=Signal%20handling%20race%20conditions%20can,installed%20to%20handle%20multiple%20signals.s
Deja de pagar por desarrollador.
Empieza a cerrar el bucle.
Plexicus es el ASPM nativo de IA que escanea, filtra, corrige, pentestea y explica — de forma autónoma. Desarrolladores ilimitados, repos ilimitados, acciones de IA de uso justo. Nivel gratuito real, €269/mo anual cuando estés listo.