CWE-831 Variante Incomplet

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.

Définition

What is 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.
When the same function handles multiple signals, an attacker can exploit timing issues by sending a second signal while the handler is still processing the first. If the handler uses shared resources like global variables or non-reentrant functions, this interruption can corrupt program state, potentially leading to crashes, denial of service, or even code execution. Even without classic race conditions, this pattern creates risk. Attackers can trigger the handler multiple times by sending different signals sequentially, causing unintended side effects. This is especially dangerous for handlers designed to run only once, as forced re-execution can bypass security controls or destabilize the application.
Impact réel

Real-world CVEs caused by CWE-831

Aucune référence CVE publique n'est liée à ce CWE dans le catalogue MITRE pour le moment.

Comment les attaquants l'exploitent

Parcours de l'attaquant étape par étape

  1. 1

    This code registers the same signal handler function with two different signals.

  2. 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. 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. 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. 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.

Exemple de code vulnérable

Vulnerable C

This code registers the same signal handler function with two different signals.

Vulnérable C
void handler (int sigNum) {
  	...
  }
  int main (int argc, char* argv[]) {
  	signal(SIGUSR1, handler)
  	signal(SIGUSR2, handler)
  }
Exemple de code sécurisé

Secure pseudo

Sécurisé pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Liste de contrôle de prévention

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.
Signaux de détection

How to detect CWE-831

SAST High

Exécuter une analyse statique (SAST) sur le code source à la recherche du motif non sécurisé dans le flux de données.

DAST Moderate

Exécuter des tests de sécurité applicative dynamique (DAST) contre le point de terminaison en ligne.

Runtime Moderate

Surveiller les journaux runtime pour détecter des traces d'exception inhabituelles, des entrées malformées ou des tentatives de contournement d'autorisation.

Code review Moderate

Revue de code : signaler tout nouveau code qui traite les entrées de cette surface sans utiliser les helpers du framework validés.

Correction automatique Plexicus

Plexicus détecte automatiquement CWE-831 et ouvre une PR de correction en moins de 60 secondes.

Codex Remedium analyse chaque commit, identifie cette faiblesse précise et livre une pull request prête à être relue avec le correctif. Pas de tickets. Pas de transferts.

Questions fréquentes

Frequently asked questions

Qu'est-ce que 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.

Quelle est la gravité de CWE-831 ?

MITRE n'a pas publié de note de probabilité d'exploitation pour cette faiblesse. Traitez-la comme un impact moyen jusqu'à ce que votre modèle de menace prouve le contraire.

Quels langages ou plateformes sont affectés par CWE-831 ?

MITRE n'a pas spécifié les plateformes affectées pour ce CWE — il peut s'appliquer à la plupart des stacks applicatives.

Comment puis-je prévenir 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.

Comment Plexicus détecte et corrige CWE-831 ?

Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-831 à chaque commit. Lorsqu'une correspondance est trouvée, notre agent Codex Remedium ouvre une PR de correction avec le code corrigé, les tests et un résumé d'une ligne pour le relecteur.

Où puis-je en savoir plus sur CWE-831 ?

MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/831.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.

Prêt quand vous l'êtes

Arrêtez de payer par développeur.
Commencez à fermer la boucle.

Plexicus est l'ASPM natif IA qui scanne, filtre, corrige, penteste et explique — de façon autonome. Développeurs illimités, dépôts illimités, actions IA à usage équitable. Vrai niveau gratuit, €269/mo annuel quand vous êtes prêt.