Skip to content
Threat Feed
high advisory

CVE-2026-70640: Race Condition Use-After-Free in llama.cpp Android JNI Wrapper

A race condition in the llama.cpp Android JNI wrapper allows attackers to trigger a use-after-free vulnerability, potentially leading to remote code execution through vtable pointer hijacking.

CVE-2026-70640 is a high-severity race condition vulnerability identified in the LLaMA-Android JNI wrapper of llama.cpp (builds b1886 through b7445). The flaw originates from insufficient synchronization between the bench_1model() and free_1context() functions. This missing synchronization allows a race condition where one thread can continue to operate on memory that has been freed by another thread during a concurrent call to free the llama_context.

An attacker can exploit this condition by performing a heap spray to plant malicious data, including a forged vtable, into the heap memory. By targeting the vtable pointer at offset +0x30, the attacker can hijack execution flow when llama_batch_allocr::clear() is subsequently called. This results in the application dereferencing an attacker-controlled pointer, which may facilitate arbitrary code execution within the context of the Android application. Defenders should prioritize updating llama.cpp to a version beyond b7445 to mitigate this risk.

Impact

The vulnerability poses a significant risk to Android applications integrating the vulnerable llama.cpp builds. Successful exploitation could allow an attacker to achieve remote code execution on the host device, leading to full application compromise, unauthorized access to local user data, or further escalation of privileges within the Android environment.

Recommendation

  • Update all Android applications utilizing llama.cpp builds between b1886 and b7445 to a patched version immediately.
  • Review crash logs for Android applications for recurring segmentation faults or memory access violations involving the llama.cpp JNI wrapper, which may indicate attempted exploitation.
  • Implement memory safety checks and sanitize JNI boundary inputs in custom Android native wrappers to reduce the likelihood of memory-related vulnerabilities.

Immediate actions

Audit Android applications for llama.cpp version usage and update affected builds

Application Security 72h