Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.
Double Free
A double free vulnerability occurs when a program mistakenly calls the 'free()' function twice on the same block of memory.
What is CWE-415?
Real-world CVEs caused by CWE-415
-
Chain: Signal handler contains too much functionality (CWE-828), introducing a race condition (CWE-362) that leads to a double free (CWE-415).
-
Double free resultant from certain error conditions.
-
Double free resultant from certain error conditions.
-
Double free resultant from certain error conditions.
-
Double free from invalid ASN.1 encoding.
-
Double free from malformed GIF.
-
Double free from malformed GIF.
-
Double free from malformed compressed data.
Parcours de l'attaquant étape par étape
- 1
The following code shows a simple example of a double free vulnerability.
- 2
Double free vulnerabilities have two common (and sometimes overlapping) causes:
- 3
- Error conditions and other exceptional circumstances - Confusion over which part of the program is responsible for freeing the memory
- 4
Although some double free vulnerabilities are not much more complicated than this example, most are spread out across hundreds of lines of code or even different files. Programmers seem particularly susceptible to freeing global variables more than once.
- 5
While contrived, this code should be exploitable on Linux distributions that do not ship with heap-chunk check summing turned on.
Vulnerable C
The following code shows a simple example of a double free vulnerability.
char* ptr = (char*)malloc (SIZE);
...
if (abrt) {
free(ptr);
}
...
free(ptr); 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-415
- Architecture and Design Choose a language that provides automatic memory management.
- Implementation Ensure that each allocation is freed only once. After freeing a chunk, set the pointer to NULL to ensure the pointer cannot be freed again. In complicated error conditions, be sure that clean-up routines respect the state of allocation properly. If the language is object oriented, ensure that object destructors delete each chunk of memory only once.
- Implementation Use a static analysis tool to find double free instances.
How to detect CWE-415
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
Plexicus détecte automatiquement CWE-415 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-415 ?
A double free vulnerability occurs when a program mistakenly calls the 'free()' function twice on the same block of memory.
Quelle est la gravité de CWE-415 ?
MITRE évalue la probabilité d'exploitation comme Élevée — cette faiblesse est activement exploitée et doit être priorisée pour la remédiation.
Quels langages ou plateformes sont affectés par CWE-415 ?
MITRE lists the following affected platforms: C, C++.
Comment puis-je prévenir CWE-415 ?
Choose a language that provides automatic memory management. Ensure that each allocation is freed only once. After freeing a chunk, set the pointer to NULL to ensure the pointer cannot be freed again. In complicated error conditions, be sure that clean-up routines respect the state of allocation properly. If the language is object oriented, ensure that object destructors delete each chunk of memory only once.
Comment Plexicus détecte et corrige CWE-415 ?
Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-415 à 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-415 ?
MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/415.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.
Weaknesses related to CWE-415
Expired Pointer Dereference
This vulnerability occurs when a program tries to use a pointer that still points to a memory location that has already been freed or…
Use After Free
Use After Free happens when a program continues to use a pointer to a memory location after that memory has been freed. This can lead to…
Write-what-where Condition
A write-what-where condition occurs when an attacker can control both the data written and the exact memory location where it's written,…
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.