flawopen.com/Teardowns/cve-2015-3824-android-stagefright-mediacodec-oob-write

● CVE-2015-3824 · CVSS v2 10.0 · 높음
보안 연구 · FlawOpen

심층 기술 분석: CVE-2015-3824: Android Stagefright MediaCodec Out-of-Bounds Write Teardown

vulnerabilidade 소스 코드 심층 기술 분석 및 시스템 보안 강화 가이드: 취약점 근본 원인과 패치 메커니즘 분석.

💡 알기 쉬운 설명 (ELI5)

직관적인 현실 비유 설명: Imagine a video projector that reads the size of each video slide from the film itself. A film has a label: 'This slide is 4 billion bytes long'. The projector calculates the size using a small pocket calculator that wraps back around to 12. It creates a tiny frame for 12 bytes, and then the film feeds 4 billion bytes into it, jamming the projector and taking over the movie theater.

핵심 개념 및 용어

libstagefright
The Android C++ multimedia parsing engine responsible for demuxing and decoding MP4, MKV, and streaming video.
NAL Unit (Network Abstraction Layer)
The packet format used to deliver H.264/AVC and H.265/HEVC video frames.
media.codec Sandbox
The isolated Linux process where video decoding hardware acceleration runs on Android.
Zero-Click Exploit
An attack that achieves remote code execution without requiring the victim to click a link or open an application.

근본 원인 분석 (Root Cause)

근본 원인은 오픈 소스 시스템의 검증되지 않은 경계 매개변수로 인해 상태 비동기화 및 보안 제어 우회가 발생한 데 있습니다.

단계별 공격 실행 흐름

Step 1

공격 실행 단계: Deliver Malicious Video

기술적 취약점 악용 메커니즘 및 상세 실행 경로: The attacker sends a crafted MP4 video via chat or MMS.

Step 2

공격 실행 단계: Background Thumbnail Parsing

기술적 취약점 악용 메커니즘 및 상세 실행 경로: Android's media scanner automatically demuxes the video without user interaction.

Step 3

공격 실행 단계: Integer Wrap in NALU Length

기술적 취약점 악용 메커니즘 및 상세 실행 경로: libstagefright adds the NAL unit size to an offset, wrapping past 32 bits.

Step 4

공격 실행 단계: Heap Buffer Overwrite & RCE

기술적 취약점 악용 메커니즘 및 상세 실행 경로: The decoder writes video data into an undersized heap buffer, achieving code execution.

소스 코드 비교: 취약한 구현 vs 보안 패치

취약한 구현
// VULNERABLE: frameworks/av/media/libstagefright/MPEG4Extractor.cpp
status_t MPEG4Extractor::parseChunk(off64_t *offset) {
    uint32_t chunk_size = readU32();
    
    // ROOT CAUSE:
    // Raw unsigned 32-bit addition wraps around!
    // If chunk_size is 0xFFFFFFF0, adding header (0x20) results in 0x10 (16 bytes!)
    uint32_t alloc_size = chunk_size + sizeof(ChunkHeader);
    
    uint8_t *buffer = (uint8_t *)malloc(alloc_size);
    // Copies full chunk_size, overflowing buffer!
    mDataSource->readAt(*offset, buffer, chunk_size);
    return OK;
}
보안 강화 패치
// SECURE: frameworks/av/media/libstagefright/MPEG4Extractor.cpp patch
status_t MPEG4Extractor::parseChunk(off64_t *offset) {
    uint32_t chunk_size = readU32();
    
    // 1. Enforce safe integer arithmetic check using __builtin_add_overflow
    uint32_t alloc_size;
    if (__builtin_add_overflow(chunk_size, sizeof(ChunkHeader), &alloc_size)) {
        return ERROR_MALFORMED; // Abort on integer overflow
    }
    
    // 2. Impose strict maximum upper bound ceiling on media chunks
    if (alloc_size > MAX_MEDIA_CHUNK_SIZE) {
        return ERROR_MALFORMED;
    }
    
    uint8_t *buffer = (uint8_t *)malloc(alloc_size);
    mDataSource->readAt(*offset, buffer, chunk_size);
    return OK;
}

엔지니어링 및 시스템 보안 강화 체크리스트

출처