Breaking the Loop: Detecting and Mitigating Denial-of-Service Vulnerabilities in Large Language Models CCS: Software and its engineering Empirical software validation
Junzhe Yu, Yi Liu, Huijia Sun, Ling Shi, Yuqi Chen · 2025
Read Breaking the Loop: Detecting and Mitigating Denial-of-Service Vulnerabilities in Large Language Models CCS: Software and its engineering Empirical software validation by Junzhe Yu, Yi Liu, Huijia Sun, Ling Shi, Yuqi Chen (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2503-00416.txt.
Introduction
A chat model that falls into a loop, saying the same thing over and over, can freeze a service for all its users. Junzhe Yu and four co-authors map that denial-of-service flaw in 2025 and build tools against it. (The catalog title trails off into a subject-tag line; the head title is clean.) Their first tool breeds prompts that trick big models into looping, working blind from outside. It found loop cases in two flagship models.
Their second tool watches the model's inner hum as it writes and flags a loop as it starts. Trained on those hum patterns, the guard hit high marks on both hits and balance. The team post both tools and their data in the open. Slow answers, they argue, are a security hole, not just a nuisance.
Catalog record
| CREATOR | Junzhe Yu, Yi Liu, Huijia Sun, Ling Shi, Yuqi Chen |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 55 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2503-00416
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
Breaking the Loop: Detecting and Mitigating Denial-of-Service Vulnerabilities in Large Language Models CCS: Software and its engineering Empirical software validation Junzhe Yu, Yi Liu, Huijia Sun, Ling Shi, Yuqi Chen Abstract . Large Language Models (LLMs) have significantly advanced text understanding and generation, becoming integral to applications across education, software development, healthcare, entertainment, and legal services. Despite considerable progress in improving model reliability, latency remains under-explored, particularly through recurrent generation—where models repeatedly produce similar or identical outputs, causing increased latency and potential Denial-of-Service (DoS) vulnerabilities. We propose RecurrentGenerator , a black-box evolutionary algorithm that efficiently identifies recurrent generation scenarios in prominent LLMs like LLama-3 and GPT-4o. Additionally, we introduce RecurrentDetector , a lightweight real-time classifier trained on activation patterns, achieving 95.24% accuracy and an F1 score of 0.87 in detecting recurrent loops. Our methods provide practical solutions to mitigate latency-related vulnerabilities, and we publicly share our tools and data to support further research. 1. Introduction Large Language Models (LLMs) have made significant advancements in understanding and generating human-like text, largely due to training on vast corpora of text. These models are increasingly being integrated into a wide range of software applications, spanning fields such as education ( zhang2024simulating ) , software development ( guo2024stopefficientcodegeneration ) , healthcare ( restrepo2024analyzing ) , entertainment ( Perplexi34:online ) , and legal services ( izzidien2024llm ) . For example, GRU ( Assistan30:online ) leverages LLMs to automatically generate code to resolve GitHub issues, achieving top rankings in the coding benchmark SWE-bench ( jimenez2024swebenchlanguagemodelsresolve ) . In these applications, interactions with LLMs—whether through offline or online systems—are essential for delivering contextually relevant responses. As a result, the quality and responsiveness of LLM-generated outputs are critical to the effectiveness of these applications. While various aspects of LLM reliability have been explored within the software engineering community (e.g., quality of code generation ( li2024cosec ) , handling glitch tokens ( 10.1145/3660799 ) , and reliability of LLM embeddings ( 10.1145/3643767 ) ), less attention has been given to an equally important factor—latency. Several factors such as the LLM type and configuration, hardware, and network conditions can influence response time in applications leveraging LLMs. However, in this work, we highlight an under-explored phenomenon known as recurrent generation in LLMs, which leads to unexpectedly long latency across mainstream models, independent of these external factors. Figure 1 . Comparison between normal and recurrent generation in Llama2-7b-chat. Recurrent generation occurs when LLMs repeatedly produce highly similar content, similar to how traditional infinite loops operate in programming ( xie2017loopster ; xie2016proteus ) . As illustrated in Figure 1 , when a user inputs a prompt with random characters into Llama2-7b-chat ( llama2 ) , the model continuously generates explanations for argument usage until it reaches the max_new_tokens limit, which defines the maximum number of tokens the model can generate. This recurrent generation phenomenon affects users, developers, and LLM service providers. Recurrent generation significantly extends latency, deteriorates user experience, and introduces the risk of Denial-of-Service (DoS) attacks. From the users’ perspective, recurrent generation leads to repetitive content, causing long wait times and diminishing the overall user experience in applications integrated with LLMs. For developers, who typically pay for LLM services based on the number of tokens consumed (e.g., in GPT-4o ( PricingO96:online ) ), detecting and mitigating recurrent generation can enhance user satisfaction and reduce costs by preventing the generation of redundant content. For LLM service providers like OpenAI ( OpenAI3:online ) , addressing recurrent generation can significantly improve the throughput of their services by reducing the length of token sequences, thereby lowering hardware usage (e.g., GPU utilization) and saving energy. However, existing work on studying recurrent generation in LLMs is limited. The most relevant concept is the “sponge example” ( sponge-example-1 ) from the pre-LLM era, where crafted text inputs caused latency degradation in neural networks, such as recurrent networks. The concept of the sponge example was first defined by Ilia et al. ( sponge-example-1 ) , who proposed a gradient-based white-box methodology to generate sponge examples that degraded the performance of systems like Microsoft Translator. Several follow-up studies optimized the efficiency of finding sponge examples ( cinà2023energylatencyattacksspongepoisoning ; shapira2023phantom ; deng2024deconstructing ) using white-box approaches. While effective for small models, generating samples that exhibit recurrent generation is particularly challenging in white-box settings for LLMs. Existing sponge example methods ( sponge-example-1 ; cinà2023energylatencyattacksspongepoisoning ) rely on gradient-based approaches that require instrumenting the LLM under test, which introduces significant runtime overhead. Additionally, gradient-based optimization itself is time-consuming. Furthermore, some LLMs, such as GPT-4o ( openai2023gpt4 ) , do not provide access to internal model states, making white-box approaches infeasible. Consequently, testing LLMs for this aspect presents a significant challenge. Additionally, detecting recurrent generation in LLMs introduces its own set of difficulties, as the underlying causes of recurrent generation remain unclear, complicating the design of effective and efficient detection methods. To tackle these challenges, we first design a black-box generation method for creating recurrent generation samples across various LLMs. Our goal is to demonstrate that this phenomenon is prevalent across different models and to efficiently generate a benchmark for the detection phase. Next, by investigating the root causes of recurrent generation, we develop a detection method to address the phenomenon effectively. Specifically, in this work, we aim to explore the following research questions: \bullet RQ1 (Recurrent Generation): How efficiently can recurrent generation be triggered in LLMs? Efficiently generating test inputs that trigger recurrent generation can help developers and LLM service providers evaluate their applications. It also provides datasets for analyzing, detecting, and mitigating recurrent generation in LLMs. In this work, we propose RecurrentGenerator , an evolutionary algorithm designed to generate such test inputs effectively. Ultimately, we identified a total of 2,388 test inputs that trigger recurrent generation in eight top LLMs, including LLama-3 ( llama3 ) and GPT-4o ( gpt4 ) . \bullet RQ2 (Characteristics): What are the characteristics of recurrent generation across different LLMs? This research question aims to provide insights into how LLMs behave internally when encountering recurrent generation. We analyze the dataset collected from RQ1 and discover that recurrent generation tends to exhibit similar activation patterns across different models. \bullet RQ3 (Detection): How effectively can we detect recurrent generation across LLMs? Based on the insights gained from RQ2, we propose RecurrentDetector , a lightweight multi-layer perceptron (MLP) trained on activation patterns to detect recurrent generation in LLMs in real-time. Contributions. We summarize our key contributions as follows: • Recurrent Generation Test Inputs. We have developed an efficient black-box evolutionary algorithm, RecurrentGenerator , to optimize and generate test inputs that trigger recurrent generation in eight top LLMs like GPT-4o and GPT-4o mini. In total, we have identified 2,388 test inputs that cause recurrent generation in these models, including LLama-3 ( llama3 ) and GPT-4o ( gpt4 ) . • New Findings. Based on the generated test inputs, we observed that recurrent generation in LLMs is associated with specific patterns in the models’ activations and hidden states when they become trapped in a recurrent loop. • Recurrent Generation Detection. Building on the insights obtained, and to the best of our knowledge, we propose the first practical detection technique, RecurrentDetector , an MLP classifier trained on activation patterns from the recurrent generation dataset. We