ggml-org llama.cpp Stack-Based Buffer Overflow Vulnerability in GBNF Grammar Handler
Vulnerability
A stack-based buffer overflow vulnerability has been identified in ggml-org llama.cpp versions prior to commit 55abc39. The issue arises in the GBNF Grammar Handler, specifically within the function llama_grammar_advance_stack, located in the file llama.cpp/src/llama-grammar.cpp. This vulnerability is triggered by nested repetition patterns in GBNF grammar, leading to infinite recursion and a stack overflow. The vulnerability must be exploited locally, and a public exploit is available.
Impact
Exploitation of this vulnerability causes a stack-based buffer overflow, leading to a denial-of-service condition where the application crashes due to exhausted stack space.
Reproduction
The vulnerability can be reproduced by loading a GBNF grammar file that contains nested repetition patterns, such as '(...*)*', into an application using ggml-org llama.cpp prior to version 55abc39. The function llama_grammar_advance_stack will recursively process the nested repetitions, leading to a stack overflow. This behavior can be observed by using the AddressSanitizer, which will detect the stack overflow and abort the program.
Remediation
Users are advised to update to the version of ggml-org llama.cpp that includes the patch for this vulnerability.
Vulnerability Rating
Our algorithm analyzes dozens of metrics to generate these 8 key vulnerability categories, which are then combined to calculate the overall risk score.
