在同一個內存地址上兩次調用 free(),會引發 buffer overflow。
當同一內存地址被當作參數不止一次地調用 free() 時,會出現 Double free 錯誤。
針對同一個值兩次調用 free(),會導致 buffer overflow。當程序使用同一參數兩次調用 free() 時,程序中的內存管理數據結構會遭到破壞。這種破壞會導致程序崩潰。有時在某些情況下,還會導致兩次調用 malloc() 延遲,而返回相同的指針。如果 malloc() 兩次都返回同一個值,稍候程序便會允許攻擊者控制整個已經寫入雙倍分配內存的數據,從而使程序更加容易受到 buffer overflow 的攻擊。
例 1:以下代碼顯示了一個關于 double free 漏洞的簡單例子。
char* ptr = (char*)malloc (SIZE);
...
if (abrt) {
free(ptr);
}
...
free(ptr);
[1] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A5 Buffer Overflow
[2] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3590.1 CAT I
[3] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3590.1 CAT I
[4] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 415
[5] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 6.5.2
[6] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.5
[7] J. Koziol et al. The Shellcoder's Handbook:Discovering and Exploiting Security Holes John Wiley & Sons