Katalog CWE

CWE-415 · Słabość

Double Free

Abstrakcja
Wariant
Status
Szkic
Ryzyko wykorzystania
wysokie
Dodano
19 lipca 2006
Ostatnia zmiana
11 grudnia 2025

Podatności CVE z tą słabościąPełny wpis na cwe.mitre.org ↗

Opis

The product calls free() twice on the same memory address.

Inne nazwy

Double-free

Skutki

  • Integrity, Confidentiality, Availability

    Modify Memory; Execute Unauthorized Code or Commands

    When a program calls free() twice with the same argument, the program's memory management data structures may become corrupted, potentially leading to the reading or modification of unexpected memory addresses. This corruption can cause the program to crash or, in some circumstances, cause two later calls to malloc() to return the same pointer. If malloc() returns the same value twice and the program later gives the attacker control over the data that is written into this doubly-allocated memory, the program becomes vulnerable to a buffer overflow attack.

    Doubly freeing memory may result in a write-what-where condition, allowing an attacker to execute arbitrary code.

Zapobieganie

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

Przykłady podatności

Słabość nadrzędna

Pokrewna

Kiedy powstaje

Dotyczy

Memory-Unsafe, C, C++

Uwagi

This is usually resultant from another weakness, such as an unhandled error or race condition between threads. It could also be primary to weaknesses such as buffer overflows.

It could be argued that Double Free would be most appropriately located as a child of "Use after Free", but "Use" and "Release" are considered to be distinct operations within vulnerability theory, therefore this is more accurately "Release of a Resource after Expiration or Release", which doesn't exist yet.

Źródła

  1. 24 Deadly Sins of Software Security — Michael Howard, David LeBlanc, John Viega, "Sin 8: C++ Catastrophes." Page 143, McGraw-Hill, 2010
  2. The Art of Software Security Assessment — Mark Dowd, John McDonald, Justin Schuh, Chapter 7, "Double Frees", Page 379, Addison Wesley, 2006
  3. The CLASP Application Security Process — Secure Software, Inc., 2005
  4. AddressSanitizer

Wpis z katalogu CWE 4.20.