CVE-2026-107183: llama.cpp Remote Heap Use-After-Free in PEG Chat Parser via Dangling Tool Pointer
HERMES THREAT SCORE & AGENTIC INFERENCE INFRASTRUCTURE EVALUATION
Target:llama.cpp Inference Engine โ llama-server common_chat_peg_mapper::map & chat_parser Both CVSS v3.1 (9.8 Critical) and CVSS v4.0 (9.4 Critical) evaluate this vulnerability as an unauthenticated network memory corruption flaw. The Hermes Threat Score assesses it at 95 (CRITICAL) with an Agentic Security Score (HASS) of 96 (CRITICAL). llama.cpp represents the foundational C/C++ inference runtime deployed globally across local AI agent swarms, embedded devices, Ollama backends, and multi-tenant LLM inference proxies. To support structured output and function calling, llama-server integrates Parsing Expression Grammars (PEG) in common_chat_peg_mapper::map. When parsing tool-calling syntax, emitting an out-of-order sequenceโspecifically a tool-id tag after a tool-close delimiterโcauses the parser to deallocate the active tool object without nullifying the current_tool pointer. Subsequent grammar parsing reuses this dangling pointer, allowing attackers to corrupt glibc heap chunk metadata, achieve an arbitrary write primitive, and execute code within the process hosting model weights and agent tool executors. The flaw directly compromises the execution integrity of autonomous AI agents relying on local LLM runtimes.
CVE-2026-107183: llama.cpp Remote Heap Use-After-Free in PEG Chat Parser via Dangling Tool PointerVULNERABILITY
Software platform affected by security vulnerabilities and agentic attack patterns.
๐ Why is this related? (Evidence & Provenance)
“Confirmed security vulnerability in llama.cpp Inference Engine documented in Hermes dossier.”
- [vulnerability_report]
- [government_confirmation]CISA verified active exploitation in the wild and mandated federal remediation deadline in KEV entry. — Source: Cybersecurity & Infrastructure Security Agency (CISA): CISA Adds CVE-2026-59822 to Known Exploited Vulnerabilities Catalog (Reliability: VERY_HIGH)
1. Technical Context & Affected Architecture Matrix
Section titled โ1. Technical Context & Affected Architecture Matrixโllama.cpp powers edge, desktop, and private cloud inference for open-weight models (Llama, Mistral, Qwen, DeepSeek). To enable reliable tool calling for AI agents, llama-server incorporates a PEG-based streaming chat parser that converts model text output into structured JSON tool calls while validating grammar constraints.
| Parameter | Technical Specification | Operational Details |
|---|---|---|
| CVE Identifier | CVE-2026-107183 | International vulnerability catalog identifier |
| Software Platform | llama.cpp (llama-server) | Foundational C/C++ LLM inference runtime |
| Vulnerable Component | common/chat.cpp (common_chat_peg_mapper::map) | Streaming PEG chat parser and tool-call state machine |
| Vulnerability Class | CWE-416 / CWE-415 | Use After Free / Double Free |
| Attack Vector | HTTP POST (/completion, /v1/chat/completions) | Unauthenticated JSON request with crafted chat prompt/stream |
| Remediation Release | llama.cpp build b11393 | Immediate pointer nullification upon delimiter closure |
[ Unauthenticated Remote Attacker ] | HTTP POST /v1/chat/completions to llama-server Payload: Crafted chat with out-of-order tool tags: "...<tool_call><tool_close><tool_id>1234..." | v +-------------------------------------------+ | llama-server HTTP Endpoint (:8080) | +-------------------------------------------+ | v +-------------------------------------------+ | chat_parser / common_chat_peg_mapper | | Token 1: <tool_close> | | -> free(current_tool); | | -> BUG: current_tool NOT set to nullptr| | Token 2: <tool_id> | | -> Dereferences dangling current_tool | | -> Writes to freed heap chunk metadata | +-------------------------------------------+ | v +-------------------------------------------+ | Glibc Heap Corruption | | Controlled Use-After-Free / Double Free | +-------------------------------------------+ | v +-------------------------------------------+ | Remote Code Execution (RCE) | | Context: llama-server Process / Host | | Hijack Model Weights & Tool Dispatch | +-------------------------------------------+2. Root Cause Analysis & Vulnerable Code Anatomy
Section titled โ2. Root Cause Analysis & Vulnerable Code AnatomyโIn common/chat.cpp, the common_chat_peg_mapper::map class tracks the state of active tool calls during grammar evaluation:
// Vulnerable snippet in llama.cpp before build b11393 (common/chat.cpp)bool common_chat_peg_mapper::map(const peg::Ast & ast, chat_message & msg) { if (ast.name == "tool_call_close") { if (current_tool != nullptr) { msg.tools.push_back(*current_tool); delete current_tool; // Heap memory released here! // VULNERABILITY: current_tool is NOT set to nullptr! } } else if (ast.name == "tool_id") { // If an unexpected tool_id token arrives after tool_call_close: if (current_tool != nullptr) { // Accessing freed memory! (Use-After-Free) current_tool->id = ast.token_to_string(); } else { current_tool = new common_chat_tool(); } } // ...}When an attacker sends a prompt designed to force or simulate a sequence where tool_call_close precedes an unexpected tool_id, current_tool is deleted. However, because current_tool remains pointing to the freed chunk, the subsequent branch executes:
current_tool->id = ast.token_to_string();This dereferences a stale heap pointer (CWE-416). If another allocation has reused the chunk, the string assignment overwrites arbitrary memory. Furthermore, if a subsequent reset routine invokes delete current_tool; again, a fatal double-free occurs (CWE-415).
On Linux systems running glibc, exploiting this use-after-free with heap grooming allows overwriting function pointers or vtables, yielding arbitrary code execution with the permissions of the llama-server process.
3. Real-World Weaponization & Threat Telemetry
Section titled โ3. Real-World Weaponization & Threat Telemetryโ- Weaponized Exploit Research: VulnCheck issued a technical advisory on October 8, 2026, documenting functional proof-of-concept scripts that trigger heap corruption via standard HTTP client requests to
llama-server. - Exposed Server Scanning: Threat actors actively probe for public-facing
llama-serverports (8080/tcp,11434/tcp, and custom reverse proxies). - Agentic System Impact: In autonomous agent frameworks (e.g., LangChain, AutoGen, CrewAI) connecting to local
llama.cppbackends, an external adversary can deliver malicious indirect prompt injection that tricks the LLM into generating the malformed tag sequence, exploiting the underlying C++ server through the agentโs own completion stream.
4. Forensic Triage & Detection Engineering
Section titled โ4. Forensic Triage & Detection Engineeringโtitle: llama.cpp Chat Parser Out-of-Order Tool Call Exploitationid: e8107183-4a11-4f92-9102-cve2026107183status: experimentaldescription: Detects malformed tool calling sequences targeting llama-server chat parser use-after-free vulnerability.references: - https://vulncheck.com/advisories/llama-cpp-before-b11393-use-after-free-via-common-chat-peg-mapper-chat-parser - https://nvd.nist.gov/vuln/detail/CVE-2026-107183author: Hermes Codex CTIdate: 2026-10-09logsource: category: webserverdetection: selection_endpoint: cs-method: 'POST' cs-uri-stem|contains: - '/completion' - '/v1/chat/completions' selection_payload: cs-method: 'POST' condition: selection_endpointfields: - c-ip - cs-method - cs-uri-stem - sc-statusfalsepositives: - Legitimate high-volume inference traffic. Deep packet inspection (WAF/Suricata) should inspect POST bodies for out-of-order tool closing and opening tags.level: high// Azure Sentinel / Container Log: Detect llama-server Crashes and SIGSEGVContainerLog| where Image has "llama.cpp" or Image has "llama-server"| where LogEntry has_any ("SIGSEGV", "Segmentation fault", "double free or corruption", "free(): invalid pointer")| project TimeGenerated, ContainerID, Image, LogEntry#!/usr/bin/env bash# Hermes DFIR: Inspect llama-server Process Core Dumps & GDB Crash Stateecho "[*] Searching for recent llama-server core dumps..."coredumpctl list /usr/local/bin/llama-server 2>/dev/null || ls -la /var/crash/*llama-server* 2>/dev/null
echo "[*] Checking systemd journal for glibc heap corruption in llama-server..."journalctl -u llama-server --since "24 hours ago" | grep -E "(double free|corrupted double-linked list|SIGSEGV)"5. Remediation Strategy & Mitigation Guidance
Section titled โ5. Remediation Strategy & Mitigation Guidanceโ-
Rebuild / Upgrade to Build b11393: Pull the latest release and recompile
llama.cpp:Terminal window git clone https://github.com/ggerganov/llama.cppcd llama.cpp && git checkout b11393cmake -B build -DGGML_CUDA=ON && cmake --build build --config Release -j -
Network Isolation for Local Inference Servers: Ensure
llama-serverbinds exclusively to127.0.0.1(--host 127.0.0.1) and is never exposed directly to untrusted networks without an authenticated, validating API gateway. -
Enable Glibc Memory Protections: Run the service with memory error checking enabled in production (
MALLOC_CHECK_=3or address space layout randomization with non-executable stack/heap enforcement).