How Effective Are They? Exploring Large Language Model Based Fuzz Driver Generation

Cen Zhang, Yaowen Zheng, Mingqiang Bai, Yeting Li, Wei Ma, Xiaofei Xie, Yuekang Li, Limin Sun, Yang Liu

TL;DR

This paper investigates the effectiveness of Large Language Models (LLMs) in automatically generating fuzz drivers for library APIs. The authors found that while LLMs show significant promise, they face challenges with complex APIs and high token costs. They also identified key prompting strategies that dramatically improve generation success, paving the way for more practical LLM-driven fuzzing.

What Problem Does This Paper Address?

Fuzz testing is a crucial technique for finding software vulnerabilities, and fuzz drivers are essential for directing fuzzers to specific library APIs. However, manually writing these drivers is a complex, time-consuming, and error-prone task. While LLMs have shown great potential in code generation, their effectiveness and limitations in generating high-quality, robust fuzz drivers remain largely unexplored. This paper aims to bridge this gap by conducting a comprehensive empirical study on using LLMs for this specific task, addressing questions about their effectiveness, challenges, optimal prompting strategies, and comparison to industry-standard drivers.

Methods

The researchers designed and evaluated six distinct prompt strategies for LLM-based fuzz driver generation. These strategies were tested across five state-of-the-art LLMs (both closed and open-source) with varying temperature settings. To assess the generated drivers, they developed a multi-stage validation framework that included:

  1. Compilation and Link Check: Ensuring the generated code is syntactically correct.
  2. Short-Term Fuzz Check: A quick fuzzing run to detect obvious issues like lack of coverage progress or immediate crashes.
  3. Effectiveness Validation: This involved two key steps:
  4. Target Bugs Filtering: Identifying and filtering out false positives by comparing against known bugs found by existing OSS-Fuzz drivers.
  5. Semantic Test: Developing API-specific tests to detect common ineffective patterns in LLM-generated drivers, ensuring they actually test the target API meaningfully.

They also conducted extensive fuzzing experiments (3.75 CPU-years) to compare LLM-generated drivers against manually written OSS-Fuzz drivers.

Datasets

The study utilized a curated dataset of 86 fuzz driver generation questions derived from 30 widely-used C projects from the OSS-Fuzz projects. Each question represented a specific library API for which a fuzz driver was needed. The researchers also leveraged existing OSS-Fuzz drivers for comparison and for identifying target bugs.

Key Insights and Ideas

  • LLMs are Promising but Not Perfect: LLM-based fuzz driver generation is a viable direction, but significant obstacles remain for practical, widespread adoption.
  • Prompting is Paramount: The choice of prompt strategy has a dramatic impact on success rates. Simple strategies like "NAIVE-1" perform poorly, while complex, iterative strategies like "ALL-ITER-K" achieve much higher success.
  • Iterative and Example-Based Prompts Shine: Strategies that involve repeating queries, providing example code snippets, and iteratively fixing errors based on feedback significantly outperform simpler approaches. Example snippets, especially from internal project tests, are particularly valuable.
  • Temperature Matters: Lower temperatures (around 0.5) generally lead to more consistent and effective driver generation, while higher temperatures can decrease performance.
  • Complexity is the Enemy: LLMs struggle with APIs that have intricate specifics, complex usage patterns, or non-trivial control flow dependencies.
  • Cost is a Concern: Generating effective drivers can be expensive due to the high number of tokens required, especially when using iterative or example-based prompting strategies.
  • Semantic Correctness is a Hurdle: LLMs often generate drivers that compile and run but don't semantically test the API correctly, leading to false positives or negatives. Automated semantic validation remains a challenge.
  • LLM Drivers Can Match Industry Standards: In terms of fuzzing outcomes (coverage and crashes), LLM-generated drivers can perform comparably to manually written OSS-Fuzz drivers, though they often use fewer APIs and lack semantic oracles.

Key Results

  • The optimal configuration achieved a 91% question solve rate (78 out of 86 questions).
  • 71% of questions required repeating the entire query process at least five times, and 45% required ten or more repetitions, highlighting the cost and iteration needed.
  • 34% of assessed APIs presented challenges related to semantic correctness, indicating a need for better validation.
  • 6% of questions (5/86) could not be resolved due to complex API dependencies requiring external setup (e.g., network servers).
  • The best prompt strategy ("ALL-ITER-K") improved the question resolve rate from 10% (NAIVE) to 91%.
  • LLM-generated drivers showed comparable fuzzing outcomes (coverage and crashes) to industry-used OSS-Fuzz drivers.
  • However, LLM drivers often used fewer APIs and lacked semantic oracles compared to OSS-Fuzz drivers.
  • The study evaluated 736,430 generated fuzz drivers at a cost of over $8,000 in token charges.

Limitations and Future Work

  • Cost Reduction: The high token cost associated with effective prompting strategies is a significant barrier to practical adoption. Future work should focus on reducing these costs.
  • Semantic Correctness: Automating the validation of semantic correctness for generated drivers is crucial.
  • Complex Dependencies: Handling APIs with complex external dependencies (e.g., requiring network services) needs more advanced solutions.
  • Generalizability: The study focused on C projects. Future work could explore the effectiveness of LLMs for fuzz driver generation in other programming languages.
  • Domain Knowledge Integration: Incorporating domain-specific knowledge (e.g., state machines for network protocols) into LLM generation could improve effectiveness.
  • Hybrid Approaches: Combining LLMs with traditional program analysis or agent-based methods could offer more robust solutions.
  • Fine-tuning: Fine-tuning LLMs specifically for fuzz driver generation could enhance both effectiveness and efficiency.
  • Memorization Threat: While evidence suggests LLMs are not simply memorizing OSS-Fuzz drivers, the possibility of memorization from training data remains a potential threat to validity, especially for older code.

Summary updated

BibTeX
@inproceedings{zhang2024how,
  author = {Cen Zhang and Yaowen Zheng and Mingqiang Bai and Yeting Li and Wei Ma and Xiaofei Xie and Yuekang Li and Limin Sun and Yang Liu},
  title = {{How Effective Are They? Exploring Large Language Model Based Fuzz Driver Generation}},
  booktitle = {ISSTA},
  year = {2024},
  doi = {10.1145/3650212.3680355},
}
Figure