Exécuter une analyse statique (SAST) sur le code source à la recherche du motif non sécurisé dans le flux de données.
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 corrupted through asynchronous execution.
What is CWE-364?
Real-world CVEs caused by CWE-364
-
Signal handler does not disable other signal handlers, allowing it to be interrupted, causing other functionality to access files/etc. with raised privileges
-
Attacker can send a signal while another signal handler is already running, leading to crash or execution with root privileges
-
unsafe calls to library functions from signal handler
-
SIGURG can be used to remotely interrupt signal handler; other variants exist
-
SIGCHLD signal to FTP server can cause crash under heavy load while executing non-reentrant functions like malloc/free.
Parcours de l'attaquant étape par étape
- 1
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.
- 2
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:
- 3
- 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.
- 4
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.
- 5
Note that this is an adaptation of a classic example as originally presented by Michal Zalewski [REF-360]; the original example was shown to be exploitable for code execution.
Vulnerable C
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.
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);} 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-364
- Requirements Use a language that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.
- Architecture and Design Design signal handlers to only set flags, rather than perform complex functionality. These flags can then be checked and acted upon within the main program loop.
- Implementation Only use reentrant functions within signal handlers. Also, use validation to ensure that state is consistent while performing asynchronous actions that affect the state of execution.
How to detect CWE-364
Exécuter des tests de sécurité applicative dynamique (DAST) contre le point de terminaison en ligne.
Surveiller les journaux runtime pour détecter des traces d'exception inhabituelles, des entrées malformées ou des tentatives de contournement d'autorisation.
Revue de code : signaler tout nouveau code qui traite les entrées de cette surface sans utiliser les helpers du framework validés.
Plexicus détecte automatiquement CWE-364 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.
Frequently asked questions
Qu'est-ce que CWE-364 ?
A signal handler race condition occurs when a program's signal handling routine is vulnerable to timing issues, allowing its state to be corrupted through asynchronous execution.
Quelle est la gravité de CWE-364 ?
MITRE évalue la probabilité d'exploitation comme Moyenne — l'exploitation est réaliste mais nécessite généralement des conditions spécifiques.
Quels langages ou plateformes sont affectés par CWE-364 ?
MITRE lists the following affected platforms: C, C++.
Comment puis-je prévenir CWE-364 ?
Use a language that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. Design signal handlers to only set flags, rather than perform complex functionality. These flags can then be checked and acted upon within the main program loop.
Comment Plexicus détecte et corrige CWE-364 ?
Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-364 à 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-364 ?
MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/364.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.
Weaknesses related to CWE-364
Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
A race condition occurs when multiple processes or threads access a shared resource simultaneously without proper coordination, creating a…
Race Condition for Write-Once Attributes
This vulnerability occurs when an untrusted software component wins a race condition and writes to a hardware register before the trusted…
Hardware Logic Contains Race Conditions
A hardware race condition occurs when security-critical logic circuits receive signals at slightly different times, creating temporary…
Race Condition within a Thread
This vulnerability occurs when two or more threads within the same application access and manipulate a shared resource (like a variable,…
Time-of-check Time-of-use (TOCTOU) Race Condition
This vulnerability occurs when a program verifies a resource's state (like a file's permissions or existence) but then uses it after that…
Context Switching Race Condition
This vulnerability occurs when an application switches between different security contexts (like privilege levels or domains) using a…
Race Condition During Access to Alternate Channel
A race condition occurs when an application opens a secondary communication channel intended for an authorized user, but fails to secure…
Permission Race Condition During Resource Copy
This vulnerability occurs when a system copies a file or resource but delays setting its final permissions until the entire copy operation…
Double Free
A double free vulnerability occurs when a program mistakenly calls the 'free()' function twice on the same block of memory.
Further reading
- MITRE — CWE-364 officiel https://cwe.mitre.org/data/definitions/364.html
- The CLASP Application Security Process https://cwe.mitre.org/documents/sources/TheCLASPApplicationSecurityProcess.pdf
- 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
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.