flawopen.com/Teardowns/cve-2023-4211-arm-mali-gpu-kernel-race-condition

● CVE-2023-4211 · CVSS 5.5 · Sedang
Riset Keamanan · FlawOpen

CVE-2023-4211: Arm Mali GPU Kernel Memory Race Condition Teardown

Analisis teknis mendalam dan mitigasi rekayasa sistem untuk vulnerabilidade: How an unlocked page table teardown in drivers/gpu/arm/midgard/mali_kbase_mem.c enabled commercial spyware to bypass Android sandboxes.

💡 Penjelasan Sederhana (ELI5)

Analogi dunia nyata: Imagine a hotel where guests return room keys to the front desk. A dishonest guest hands in their key, and while the clerk is marking the room empty in the computer, the guest's accomplice runs into the room, replaces the door lock with their own, and starts renting out the room privately without the hotel knowing.

Konsep Kunci & Istilah

Mali kbase Driver
The Linux kernel module interfacing Arm Mali GPU cores with user-space rendering libraries.
Page Table Mapping (mmap)
Mapping GPU hardware physical memory pages into user-space process virtual memory addresses.
Race Condition
A timing bug where two execution threads attempt to access and modify shared resources simultaneously without adequate synchronization.
Privilege Escalation
Gaining kernel execution privileges from an unprivileged sandbox application.

Analisis Akar Masalah (Root Cause)

Akar masalah bermula dari parameter batas yang tidak divalidasi pada sistem open source, yang memungkinkan desinkronisasi status dan bypass kontrol keamanan.

Alur Serangan Langkah demi Langkah

Step 1

Tahap serangan: Multi-Threaded Memory Allocation

Mekanisme eksploitasi teknis dan detail eksekusi: The attacker launches two threads mapping GPU memory chunks via mmap().

Step 2

Tahap serangan: Race Unmap Against Access

Mekanisme eksploitasi teknis dan detail eksekusi: Thread A invokes munmap() while Thread B simultaneously queues GPU drawing commands on the same region.

Step 3

Tahap serangan: Free Memory Access

Mekanisme eksploitasi teknis dan detail eksekusi: The kernel frees the memory pages, but Thread B's GPU commands execute against the freed pages.

Step 4

Tahap serangan: Kernel Control Hijack

Mekanisme eksploitasi teknis dan detail eksekusi: The attacker sprays page tables into the slot, rewriting GPU descriptors to access all physical device RAM.

Kode Sumber: Rentan vs Aman

IMPLEMENTASI RENTAN
// VULNERABLE: drivers/gpu/arm/midgard/mali_kbase_mem.c
int kbase_mem_free(struct kbase_context *kctx, u64 gpu_addr) {
    struct kbase_va_region *reg = kbase_region_tracker_find(kctx, gpu_addr);
    
    // ROOT CAUSE:
    // Memory region is unmapped and freed WITHOUT holding the context's page lock!
    // Concurrent GPU commands can still dereference 'reg' while it is being destroyed!
    kbase_gpu_vm_lock(kctx);
    kbase_mem_free_region(kctx, reg); // Frees underlying pages
    kbase_gpu_vm_unlock(kctx);
    return 0;
}
PERBAIKAN AMAN & KUAT
// SECURE: drivers/gpu/arm/midgard/mali_kbase_mem.c patch
int kbase_mem_free(struct kbase_context *kctx, u64 gpu_addr) {
    // 1. Acquire global context lock BEFORE looking up region
    kbase_gpu_vm_lock(kctx);
    
    struct kbase_va_region *reg = kbase_region_tracker_find(kctx, gpu_addr);
    if (!reg) {
        kbase_gpu_vm_unlock(kctx);
        return -EINVAL;
    }
    
    // 2. Wait for all in-flight GPU job chains to complete before deallocating
    kbase_wait_for_in_flight_jobs(kctx, reg);
    
    kbase_mem_free_region(kctx, reg);
    kbase_gpu_vm_unlock(kctx);
    return 0;
}

Daftar Periksa Penguatan Sistem Rekayasa

Sumber