계: Code Quality

코드 품질이 낮으면 예측할 수 없는 동작이 발생합니다. 사용자 입장에서는 사용 편의성이 떨어지는 것으로 나타나는 경우가 많습니다. 공격자에게는 예상치 못한 방법으로 시스템에 부담을 줄 수 있는 기회가 됩니다.

1 개 항목 찾음
취약점
Abstract
같은 메모리 주소에서 free()를 두 번 호출하면 buffer overflow가 발생할 수 있습니다.
Explanation
메모리 주소에서 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);


Double free 취약점에는 다음의 두 가지 일반적인(때로는 겹치기도 하는) 원인이 있습니다.

- 오류 조건 및 기타 예외 상황.

- 프로그램의 어떤 부분이 메모리 해제를 담당하고 있는지에 대한 혼란.

일부 double free 취약점은 앞의 예제보다 크게 복잡하지 않지만 대부분은 수백 줄의 코드 또는 다른 파일에까지 흩어져 있습니다. 프로그래머는 특히 전역 변수를 두 번 이상 해제하는 실수를 자주 범하는 것 같습니다.
References
[1] J. Koziol et al. The Shellcoder's Handbook: Discovering and Exploiting Security Holes John Wiley & Sons
[2] Standards Mapping - Common Weakness Enumeration CWE ID 415
[3] Standards Mapping - Common Weakness Enumeration Top 25 2019 [1] CWE ID 119
[4] Standards Mapping - Common Weakness Enumeration Top 25 2020 [5] CWE ID 119
[5] Standards Mapping - Common Weakness Enumeration Top 25 2021 [17] CWE ID 119
[6] Standards Mapping - Common Weakness Enumeration Top 25 2022 [19] CWE ID 119
[7] Standards Mapping - Common Weakness Enumeration Top 25 2023 [17] CWE ID 119
[8] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-002824
[9] Standards Mapping - General Data Protection Regulation (GDPR) Indirect Access to Sensitive Data
[10] Standards Mapping - Motor Industry Software Reliability Association (MISRA) C Guidelines 2012 Rule 21.3
[11] Standards Mapping - Motor Industry Software Reliability Association (MISRA) C++ Guidelines 2008 Rule 18-4-1
[12] Standards Mapping - NIST Special Publication 800-53 Revision 4 SI-16 Memory Protection (P1)
[13] Standards Mapping - NIST Special Publication 800-53 Revision 5 SI-16 Memory Protection
[14] Standards Mapping - OWASP Top 10 2004 A5 Buffer Overflow
[15] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 Requirement 6.5.5
[16] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 Requirement 6.5.2
[17] Standards Mapping - Payment Card Industry Data Security Standard Version 3.0 Requirement 6.5.2
[18] Standards Mapping - Payment Card Industry Data Security Standard Version 3.1 Requirement 6.5.2
[19] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2 Requirement 6.5.2
[20] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2.1 Requirement 6.5.2
[21] Standards Mapping - Payment Card Industry Data Security Standard Version 4.0 Requirement 6.2.4
[22] Standards Mapping - Payment Card Industry Software Security Framework 1.0 Control Objective 4.2 - Critical Asset Protection
[23] Standards Mapping - Payment Card Industry Software Security Framework 1.1 Control Objective 4.2 - Critical Asset Protection
[24] Standards Mapping - Payment Card Industry Software Security Framework 1.2 Control Objective 4.2 - Critical Asset Protection
[25] Standards Mapping - Security Technical Implementation Guide Version 3.1 APP3590.1 CAT I
[26] Standards Mapping - Security Technical Implementation Guide Version 3.4 APP3590.1 CAT I
[27] Standards Mapping - Security Technical Implementation Guide Version 3.5 APP3590.1 CAT I
[28] Standards Mapping - Security Technical Implementation Guide Version 3.6 APP3590.1 CAT I
[29] Standards Mapping - Security Technical Implementation Guide Version 3.7 APP3590.1 CAT I
[30] Standards Mapping - Security Technical Implementation Guide Version 3.9 APP3590.1 CAT I
[31] Standards Mapping - Security Technical Implementation Guide Version 3.10 APP3590.1 CAT I
[32] Standards Mapping - Security Technical Implementation Guide Version 4.2 APSC-DV-002590 CAT I
[33] Standards Mapping - Security Technical Implementation Guide Version 4.3 APSC-DV-002590 CAT I
[34] Standards Mapping - Security Technical Implementation Guide Version 4.4 APSC-DV-002590 CAT I
[35] Standards Mapping - Security Technical Implementation Guide Version 4.5 APSC-DV-002590 CAT I
[36] Standards Mapping - Security Technical Implementation Guide Version 4.6 APSC-DV-002590 CAT I
[37] Standards Mapping - Security Technical Implementation Guide Version 4.7 APSC-DV-002590 CAT I
[38] Standards Mapping - Security Technical Implementation Guide Version 4.8 APSC-DV-002590 CAT I
[39] Standards Mapping - Security Technical Implementation Guide Version 4.9 APSC-DV-002590 CAT I
[40] Standards Mapping - Security Technical Implementation Guide Version 4.10 APSC-DV-002590 CAT I
[41] Standards Mapping - Security Technical Implementation Guide Version 4.11 APSC-DV-002590 CAT I
[42] Standards Mapping - Security Technical Implementation Guide Version 4.1 APSC-DV-002590 CAT I
[43] Standards Mapping - Security Technical Implementation Guide Version 5.1 APSC-DV-002590 CAT I
[44] Standards Mapping - Security Technical Implementation Guide Version 5.2 APSC-DV-002590 CAT I
[45] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002590 CAT I
desc.controlflow.cpp.double_free