Skip to content

CVE-2026-107183: llama.cpp Remote Heap Use-After-Free in PEG Chat Parser via Dangling Tool Pointer

Density:
HERMES

HERMES THREAT SCORE & AGENTIC INFERENCE INFRASTRUCTURE EVALUATION

Target: llama.cpp Inference Engine โ€” llama-server common_chat_peg_mapper::map & chat_parser
Confidence: 98%
95 / 100
CRITICAL

Measures real-world operational relevance, exploit weaponization, and active threat posture.

Dimension Breakdown
Exploitability 20 / 20
Threat Activity 18 / 20
Weaponization 20 / 20
Exposure 19 / 20
Prevalence 18 / 20
Impact 20 / 20
Exploit Maturity 20 / 20
Attack Chain Potential 20 / 20
โš–๏ธ Divergence & Operational Rationale

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.

๐Ÿ•ธ๏ธ Connected Knowledge Graph & Provenance

CVE-2026-107183: llama.cpp Remote Heap Use-After-Free in PEG Chat Parser via Dangling Tool PointerVULNERABILITY

Connected Nodes: 1
Active Relationships (Outgoing)
→ affectsPRODUCTllama.cpp Inference Engine
98% VERY_HIGH

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.”

Supporting Verified Evidence:

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.

ParameterTechnical SpecificationOperational Details
CVE IdentifierCVE-2026-107183International vulnerability catalog identifier
Software Platformllama.cpp (llama-server)Foundational C/C++ LLM inference runtime
Vulnerable Componentcommon/chat.cpp (common_chat_peg_mapper::map)Streaming PEG chat parser and tool-call state machine
Vulnerability ClassCWE-416 / CWE-415Use After Free / Double Free
Attack VectorHTTP POST (/completion, /v1/chat/completions)Unauthenticated JSON request with crafted chat prompt/stream
Remediation Releasellama.cpp build b11393Immediate 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 |
+-------------------------------------------+

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.


  1. 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.
  2. Exposed Server Scanning: Threat actors actively probe for public-facing llama-server ports (8080/tcp, 11434/tcp, and custom reverse proxies).
  3. Agentic System Impact: In autonomous agent frameworks (e.g., LangChain, AutoGen, CrewAI) connecting to local llama.cpp backends, 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.

title: llama.cpp Chat Parser Out-of-Order Tool Call Exploitation
id: e8107183-4a11-4f92-9102-cve2026107183
status: experimental
description: 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-107183
author: Hermes Codex CTI
date: 2026-10-09
logsource:
category: webserver
detection:
selection_endpoint:
cs-method: 'POST'
cs-uri-stem|contains:
- '/completion'
- '/v1/chat/completions'
selection_payload:
cs-method: 'POST'
condition: selection_endpoint
fields:
- c-ip
- cs-method
- cs-uri-stem
- sc-status
falsepositives:
- 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

  1. Rebuild / Upgrade to Build b11393: Pull the latest release and recompile llama.cpp:

    Terminal window
    git clone https://github.com/ggerganov/llama.cpp
    cd llama.cpp && git checkout b11393
    cmake -B build -DGGML_CUDA=ON && cmake --build build --config Release -j
  2. Network Isolation for Local Inference Servers: Ensure llama-server binds exclusively to 127.0.0.1 (--host 127.0.0.1) and is never exposed directly to untrusted networks without an authenticated, validating API gateway.

  3. Enable Glibc Memory Protections: Run the service with memory error checking enabled in production (MALLOC_CHECK_=3 or address space layout randomization with non-executable stack/heap enforcement).