In early 2023, a critical vulnerability was discovered in the Android Linux Kernel's Binder driver, specifically in the binder_vma_close function of binder.c. Tracked as CVE-2023-20928, this flaw opens the door for local attackers to escalate privileges on affected devices. Let’s break down what happened, how it works, and what you should know—even if you aren’t a hardcore kernel hacker.
What is CVE-2023-20928?
CVE-2023-20928 exists due to improper locking in the Android Kernel Binder driver. Simply put, there was a window where memory could be freed (use-after-free), but some code paths would still try to use it. That’s a recipe for an attacker to inject their data or code into a privileged context.
Official References
- Android Security Bulletin June 2023
- Upstream Kernel Patch Commit
What is Use-After-Free?
A *use-after-free (UAF)* vulnerability happens when a program still uses a region of memory after it has been returned to the system (freed). In the kernel, this can give attackers a way to get the kernel to operate on malicious data, often leading to privilege escalation.
Where Did it Happen?
The bug was inside the freeing logic of virtual memory areas (VMA) connected to Binder, Android's core inter-process communication mechanism.
The Vulnerable Code (Simplified)
// From drivers/android/binder.c (before patch)
static void binder_vma_close(struct vm_area_struct *vma) {
struct binder_proc *proc = vma->vm_private_data;
// ... omitted lines
kfree(proc); // Memory is freed here
// Some operations may still reference 'proc' here (UAF risk!)
}
The kernel would free proc, but in some race conditions, another thread could still access it.
Fixed Code (Simplified)
// After patch
static void binder_vma_close(struct vm_area_struct *vma) {
struct binder_proc *proc = vma->vm_private_data;
// Correct locking here ensures no concurrent access
mutex_lock(&proc->vma_lock);
// Safe cleanup operations
mutex_unlock(&proc->vma_lock);
kfree(proc);
}
By adding proper locking (mutex_lock/mutex_unlock), concurrent access is prevented while cleaning up.
Find a Process with Binder Memory: The attacker finds a process with a mapped Binder VMA.
2. Trigger Unmap/Race: They trigger the VMA to be closed, releasing the memory.
3. Race Condition / Controlled Allocation: By racing or manipulating the memory allocator, the attacker gets their own data placed into the just-freed area.
4. Force Use-After-Free: Another operation in the kernel uses the already-freed memory, but now it's under attacker's control.
5. Privilege Escalation: By carefully crafting the replaced memory, kernel code could run with escalated (root) privileges.
This exploit requires no additional privileges and no user interaction.
Allocate memory of the same size hoping the kernel reuses the freed region.
4. Use secondary thread or a specially crafted Binder transaction to force the kernel to act on the now attacker-controlled memory region.
PoC Snippet (for demonstration only)
int fd = open("/dev/binder", O_RDWR);
void *map = mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, );
// ... use map with a binder transaction
munmap(map, MAP_SIZE); // triggers vma_close vulnerable path
// Allocate memory of same size to reclaim freed area
char *evil = malloc(MAP_SIZE);
// Fill 'evil' with controlled data, hoping kernel uses it
// Now, trigger a binder action that dereferences the UAF pointer
This is a simplification. A real exploit would use tight threads and precise heap/memory spray, but you get the idea.
Who is Vulnerable?
- Devices running unpatched Android kernels with the vulnerable version of binder.c (mostly before June 2023).
Update your device: Make sure your device runs security patches from June 2023 or later.
- OEMs and ROM developers: Patch your kernels ASAP. Consult this upstream patch.
- Developers: Never trust a single thread context in kernel drivers! Always lock shared structures before cleaning them up.
Further Reading
- CVE-2023-20928 on NVD
- Android’s Kernel Hardening
Summary
CVE-2023-20928 shows how a seemingly small race condition in the memory cleanup of Binder can open the door to devastating privilege escalation attacks on Android. With proper locking and prompt vendor patches, this sort of risk can be tightly controlled—but it’s a powerful lesson for all system developers: memory management in the kernel is a minefield if not handled with extreme care.
Timeline
Published on: 01/26/2023 21:18:00 UTC
Last modified on: 02/06/2023 19:15:00 UTC