Back

LLM04: Model Denial of Service - Overview

Table of Contents

What is Model Denial of Service?

Model Denial of Service (DoS) occurs when attackers manipulate inputs or exploit the resource-intensive nature of Large Language Models to cause service degradation, excessive resource consumption, or complete system unavailability. Unlike traditional DoS attacks that flood network bandwidth, Model DoS exploits the computational characteristics of AI systems.

Core Concept

Model DoS attacks exploit the unique resource demands of LLMs:

``

[Malicious Input] → [LLM Processing] → [Resource Exhaustion]

↓ ↓ ↓

Crafted to be Heavy computation Service degradation

resource-heavy Long processing System unavailability

Memory overflow Cost explosion

`

The fundamental issue is unbounded or poorly managed resource consumption during model inference.

Why Does This Matter?

Model Denial of Service is ranked #4 in the OWASP Top 10 for LLM Applications because it can render AI services unavailable, cause financial damage, and impact user experience at scale.

The Business Impact

  • Service Unavailability: Users cannot access AI-powered features
  • Financial Damage: Excessive API costs from cloud providers
  • Resource Waste: Computing resources exhausted on malicious requests
  • Reputation Loss: Poor user experience and service reliability
  • Cascading Failures: DoS on AI service impacts dependent systems
  • Economic Denial: Competitors can increase operational costs

The Technical Impact

  • CPU/GPU Exhaustion: Model inference consumes all available compute
  • Memory Overflow: Large contexts cause out-of-memory errors
  • Queue Saturation: Request queues fill up, blocking legitimate users
  • Timeout Cascades: Long-running requests trigger cascading timeouts
  • Cost Explosion: Pay-per-token models become financially unsustainable
  • Thread Starvation: All worker threads blocked on slow requests

Technical Context

The LLM Resource Consumption Model

`

[User Input] → [Tokenization] → [Model Inference] → [Response Generation]

↓ ↓ ↓ ↓

Length Token count O(n²) attention Token generation

Complexity Vocabulary Memory allocation Sampling steps

Compute cycles

`

Resource Characteristics of LLMs

1. Quadratic Attention Complexity

`

Computational Cost ∝ (Input Length)²

Example:

  • 100 tokens: ~10,000 operations
  • 1,000 tokens: ~1,000,000 operations
  • 10,000 tokens: ~100,000,000 operations

10x input → 100x computation

`

2. Memory Requirements

`

Memory Usage = Model Size + Context Size + Activation Memory

Example (GPT-3 scale):

  • Model Parameters: 175B × 2 bytes = 350GB
  • Context (8K tokens): ~8K × 12KB = 96MB per request
  • Activations: ~2-4GB per request

100 concurrent requests = ~10TB memory needed

`

3. Sequential Token Generation

`

Output generation is inherently serial:

  • Each token depends on previous tokens
  • Cannot be fully parallelized
  • Long outputs = proportionally long time

1000-token output ≈ 1000 sequential steps

`

Attack Vectors

1. Input Length Exploitation

`python

Attacker sends maximum-length inputs

malicious_input = "a " * 100000 # Near token limit

Model processes O(n²) operations

CPU/GPU maxed out for extended period

response = llm.generate(malicious_input)

`

2. Complex Query Patterns

`python

Nested, complex instructions

malicious_prompt = """

Analyze the following text and for each word:

  1. Provide etymology
  2. List synonyms
  3. Give examples
  4. Translate to 50 languages
  5. Explain usage in literature

[Repeat for 1000 words...]

"""

Forces extensive processing per word

`

3. Repetitive Requests

`python

Flood with expensive requests

import asyncio

async def attack():

tasks = []

for i in range(10000):

# Each request is expensive

task = llm.generate("Write a 10000-word essay about...")

tasks.append(task)

await asyncio.gather(*tasks)

`

4. Variable-Length Output Exploitation

`python

Request maximum output length

prompt = "List all prime numbers up to 1000000"

Model generates extremely long response

Consumes resources for entire generation

`

Real-World Impact

Case Study 1: ChatGPT Service Degradation (2023)

Incident: ChatGPT experienced multiple service outages due to overwhelming demand. Attack Vector:
  • Legitimate and malicious traffic exceeded capacity
  • Complex queries consumed disproportionate resources
  • Concurrent requests caused memory saturation
Impact:
  • Service unavailable for millions of users
  • Extended downtime periods
  • User frustration and trust erosion
Lesson: Even legitimate high demand can create DoS conditions without proper rate limiting and resource management.

Case Study 2: API Cost Exploitation

Incident: Organization using GPT-4 API experienced unexpected $100K+ bill. Attack Vector:
  • API key leaked in public repository
  • Attackers scripted automated requests
  • Each request used maximum token limits
  • Ran continuously for days undetected
Impact:
  • Massive unexpected costs
  • Budget exhaustion
  • Service had to be shut down
  • Investigation and remediation costs
Lesson: API key protection and cost monitoring are critical security controls.

Case Study 3: Recursive Prompt Injection DoS

Incident: Research demonstration showed recursive prompts causing resource exhaustion. Attack Vector:
  • Prompt instructs model to generate more prompts
  • Each generated prompt fed back to model
  • Creates exponential resource consumption
  • System resources exhausted quickly
Impact:
  • Proof of concept for recursive attacks
  • Demonstrates need for recursion limits
  • Shows vulnerability of autonomous agents
Lesson: Recursive or self-referential patterns need strict limits.

Common Scenarios

Scenario 1: Unbounded Context Length

`python

VULNERABLE: No input length validation

def process_user_input(user_text):

# User can send arbitrarily long input

response = llm_api.generate(

prompt=user_text, # Could be 100,000 tokens

max_tokens=4096

)

return response

Attacker sends maximum-length input

massive_input = "tell me about " + ("quantum physics " * 50000)

process_user_input(massive_input) # Causes extreme resource usage

`

Scenario 2: No Rate Limiting

`python

VULNERABLE: No rate limiting on expensive operations

@app.route('/api/analyze')

def analyze_text():

text = request.json['text']

# No rate limiting

# No request throttling

# No user limits

# Expensive operation available to all

result = llm.analyze(text, depth='comprehensive')

return jsonify(result)

Attacker floods endpoint

for i in range(10000):

requests.post('/api/analyze', json={'text': long_text})

`

Scenario 3: Unconstrained Output Length

`python

VULNERABLE: User controls output length

def generate_content(prompt, requested_length):

# User can request arbitrarily long output

response = llm.generate(

prompt=prompt,

max_tokens=requested_length # Could be 100,000

)

return response

Attacker requests maximum output

generate_content(

"Write detailed analysis",

requested_length=100000 # Maximum possible

)

`

Scenario 4: Complex Prompt Patterns

`python

VULNERABLE: No complexity validation

def process_instruction(user_prompt):

# Accepts arbitrarily complex instructions

result = llm.complete(user_prompt)

return result

Attacker sends computationally expensive prompt

complex_prompt = """

For each character in this 10000-word text:

  • Analyze grammatical role
  • Provide phonetic breakdown
  • List historical usage
  • Generate related words
  • Translate to 100 languages

[10000 words of text...]

"""

process_instruction(complex_prompt)

`

Scenario 5: Recursive Agent Calls

`python

VULNERABLE: No recursion limits

def autonomous_agent(task):

# Agent can call itself recursively

response = llm.generate(task)

if "subtask:" in response:

# Recursively process subtasks

subtask = extract_subtask(response)

return autonomous_agent(subtask) # No depth limit!

return response

Prompt that creates recursive loop

malicious_task = "Break this task into subtasks, then break each subtask into more subtasks..."

autonomous_agent(malicious_task) # Stack overflow / resource exhaustion

``

Key Takeaways

For Security Teams

  1. Implement Rate Limiting
    • Request frequency limits per user/IP
    • Concurrent request limits
    • Resource consumption quotas
  1. Resource Monitoring
    • Track CPU/GPU/memory usage
    • Monitor request queue depth
    • Alert on anomalous patterns
  1. Input Validation
    • Enforce maximum input lengths
    • Validate prompt complexity
    • Reject malformed requests
  1. Output Controls
    • Cap maximum output tokens
    • Timeout long-running requests
    • Progressive response generation

For Developers

  1. Enforce Limits
    • Maximum input token count
    • Maximum output token count
    • Request timeout values
    • Concurrent request limits per user
  1. Implement Throttling
    • Exponential backoff for retries
    • Queue management
    • Priority-based processing
    • Fair resource allocation
  1. Cost Management
    • Token usage tracking
    • Budget alerts
    • User quotas
    • Cost attribution
  1. Graceful Degradation
    • Return partial results on timeout
    • Queue requests during high load
    • Provide status updates
    • Clear error messages

For Organizations

  1. Capacity Planning
    • Estimate token usage patterns
    • Plan for peak load
    • Reserve emergency capacity
    • Scale resources appropriately
  1. Monitoring Infrastructure
    • Real-time resource monitoring
    • Cost tracking dashboards
    • Performance metrics
    • Anomaly detection
  1. Incident Response
    • DoS detection procedures
    • Mitigation playbooks
    • Communication plans
    • Recovery processes
  1. Architecture Design
    • Load balancing
    • Request queuing
    • Circuit breakers
    • Fallback mechanisms

Critical Points

---

Remember: LLMs are computationally expensive by nature. Without proper resource controls, rate limiting, and monitoring, even legitimate usage patterns can create denial of service conditions. Design for security and scalability from the start.