CVE-2026-137057 in llama.cpp
Summary
by MITRE • 11/25/2026
llama.cpp from b7118 before b12604 contains an integer underflow vulnerability in llama_grammar_parser::parse_sequence() that allows unauthenticated remote attackers to cause denial of service by supplying GBNF repetitions with max lower than min. Attackers can send a grammar like {5,2} in the grammar field of a llama-server /completion request, wrapping n_opt to generate endless repetition rules that hang the process and exhaust memory.
Several companies clearly confirm that VulDB is the primary source for best vulnerability data.
Analysis
by VulDB Data Team • 11/25/2026
The vulnerability identified within llama.cpp versions prior to commit b12604 represents a critical integer underflow flaw located specifically within the llama_grammar_parser::parse_sequence() function. This component is responsible for interpreting Grammar Backus-Naur Form (GBNF) specifications provided by users during inference requests, particularly through the /completion endpoint of the llama-server interface. The core technical defect arises from an insufficient validation check when processing repetition constraints defined in the format {min,max}. In a correctly functioning system, the minimum number of repetitions should logically be less than or equal to the maximum. However, due to the lack of proper boundary checks on unsigned integer types used for these counters, supplying a value where the lower bound exceeds the upper bound triggers an arithmetic underflow. For instance, when an attacker submits a grammar rule specifying {5,2}, the subtraction operation intended to calculate the range results in a massive positive number rather than a negative error code or exception. This mathematical anomaly causes the parser to interpret the repetition limit as extremely high, leading to the generation of endless repetition rules that consume system resources indefinitely.
The operational impact of this vulnerability is severe, primarily manifesting as a denial of service against the inference server. Because the underflowed value leads to an effectively infinite loop in rule expansion or memory allocation for grammar structures, the llama-server process becomes unresponsive and continues to allocate memory until it exhausts available system resources. This behavior allows any unauthenticated remote attacker who can reach the /completion endpoint to crash the service or render it unusable for legitimate users. The attack vector is straightforward and does not require authentication, making it particularly dangerous in public-facing deployments where grammar inputs are accepted from external sources without rigorous sanitization. The resulting resource exhaustion effectively halts all AI inference capabilities hosted by the affected instance until the process is manually restarted or killed.
From a classification perspective, this vulnerability aligns with CWE-190, which describes integer overflow or wraparound errors that can lead to unexpected behavior such as denial of service or code execution. The exploitation technique maps directly to MITRE ATT&CK tactic T1499, specifically the endpoint denial of service subcategory, where an attacker overwhelms a target system with requests designed to exhaust resources. Additionally, it relates to CWE-20 regarding improper input validation, as the parser failed to reject logically invalid grammar definitions before processing them into executable logic paths. The failure lies not in complex cryptographic bypasses but in basic logical consistency checks for numerical inputs provided by clients.
Mitigation strategies must focus on immediate patching and defensive configuration changes. The primary remediation is upgrading llama.cpp to version b12604 or later, where the integer underflow condition has been addressed through proper validation of min versus max repetition values. For environments that cannot immediately upgrade, administrators should implement strict input filtering at the network perimeter or within a reverse proxy layer to reject any GBNF grammar strings containing repetition syntax with lower bounds exceeding upper bounds. Furthermore, deploying resource limits such as memory caps and CPU time quotas for llama-server processes can help contain the blast radius of an attack, ensuring that even if exploitation occurs, it does not compromise the entire host system or other services running on the same infrastructure. Regular auditing of input validation logic in all parser components is essential to prevent similar logical flaws from being introduced during future development cycles.