Breaking Local AI Runtimes - Exploiting llama cpp and Ollama
Where
Main Stage
DEF CON 34
Duration
46 min
Walks through three native-code memory bugs in llama.cpp and Ollama, from an Android JNI use-after-free to a Go/C out-of-bounds heap read.
Summary
The talk treats local AI inference runtimes such as llama.cpp and Ollama as ordinary native code, where memory management happens outside the language safety that surrounds it. The presenters split their research across three trust boundaries: the JNI bridge used by Android apps, the HTTP server's model lifecycle, and the Go-to-C interface inside Ollama. They stress that the work is about exploiting the runtime itself, not prompt injection.
On Android, a race between model unload and a benchmark routine leaves a freed context in use. The team reclaims the freed allocation with attacker-chosen contents, redirects a virtual call, and demonstrates code execution inside the host app. In the llama.cpp server, an idle-unload feature can free a model while request handlers still hold a pointer to its vocabulary. They reclaim that chunk remotely across threads and reach an attacker-controlled dereference, but stop short of full remote code execution because they still lack an address leak to defeat ASLR. In Ollama, crafted GGUF tensor shapes make quantization read past a Go-backed buffer. By choosing a conversion path that preserves data, the leaked heap contents survive into the saved model.
The practical takeaways are to avoid idle unloading on exposed servers, place authenticated TLS proxies in front of them, validate every size read from a model file, and use checked arithmetic. Audit unsafe and cgo boundaries for the same patterns. Vendor responses were uneven, and some upstream patches were closed, so the speakers published their fixes.
Related talks
Main Stage·37 min
Marcos Bajo · Rivik Goyal
Shows how Linux signal-handling flaws let an attacker chain segfaults into arbitrary code execution that bypasses Intel CET shadow stacks.
Main Stage·48 min
G Zhong · Z Liu · J Yu
Shows how a single crafted browser link can launch Electron desktop apps and chain them across processes into full remote code execution.
Main Stage·48 min
Nikos Vourdas · Kyprianos Vasilopoulos
Shows how an SMS gateway's trust assumptions and code bugs let attackers suppress, forge, and read one-time passcodes in transit.


