The Seeds of the FUTURE Sprout from History: Fuzzing for Unveiling Vulnerabilities in Prospective Deep-Learning Libraries

Zhiyuan Li, Jingzheng Wu, Xiang Ling, Tianyue Luo, Zhiqing Rui, Yanjun WuarXiv 2024 · OpenReview

TL;DR

This paper introduces FUTURE, a novel fuzzing framework designed to find bugs in new and emerging deep learning (DL) libraries. By leveraging historical bug data from established libraries and fine-tuning Large Language Models (LLMs), FUTURE effectively generates test cases for these nascent libraries, significantly improving bug detection and API coverage.

What Problem Does This Paper Address?

The rapid growth of AI, particularly with the rise of Large Language Models (LLMs), has led to an explosion in the development and adoption of Deep Learning (DL) libraries. While established libraries like PyTorch and TensorFlow are well-tested, newer libraries from tech giants like Apple (MLX), Huawei (MindSpore), and OneFlow are emerging. These new libraries, crucial for innovation, often lack mature testing methodologies, making them vulnerable to bugs that could impact downstream AI systems. Existing fuzzing tools struggle with these new libraries due to:

  • Lack of Target Flexibility: Most fuzzers are tailored for existing libraries and require extensive effort to adapt.
  • Inability to Test Bug-Prone API Sequences: Many fuzzers focus on individual API calls, missing complex bugs arising from sequences of API interactions.
  • Limited Information: New libraries often have sparse documentation and few code examples, making it hard for fuzzers to gather necessary information.
  • LLM Knowledge Lag: Pre-trained LLMs take time to incorporate knowledge about newly released libraries, limiting the effectiveness of LLM-based fuzzers.

Methods

FUTURE tackles these challenges with a multi-stage approach:

  1. Historical Bug Collection: A label-specific spider crawls GitHub issues from established DL libraries (PyTorch, TensorFlow) to extract code snippets that reproduce known bugs. These become "historical bug codes."
  2. Fine-tuning and Seed Code Generation:
    • Target Library Information Extraction: FUTURE gathers API documentation and code examples from the new target libraries.
  3. Prompt Construction: A universal prompt template is used to guide LLMs (specifically CodeLlama) to generate code pairs that map APIs from source libraries to their equivalents in target libraries. This process also considers edge cases like NaNs and Infs.
  4. Dataset Construction: The generated code pairs are used to create two datasets: one for code generation (teaching the LLM to write code for the target library) and one for code conversion (teaching it to translate code from source to target libraries).
  5. LLM Fine-tuning: The LLMs are fine-tuned using these datasets. This specialized fine-tuning allows the LLMs to understand the nuances of new libraries and convert historical bug patterns.
  6. Seed Code Generation: The fine-tuned LLMs then convert historical bug codes into seed code for the target libraries and generate new code snippets that call target library APIs. These form the "seed codes" for fuzzing.
  7. Test Oracle: The generated seed codes are executed on the target DL libraries. Crashes, segmentation faults, runtime errors, and inconsistencies across different computational backends (CPU/GPU) are monitored to identify potential bugs.

A key innovation is the "cycle from history to future and back": FUTURE uses historical bugs to find bugs in new libraries, and then uses bugs found in new libraries to potentially improve the security of older ones.

Datasets

  • Source Libraries: PyTorch and TensorFlow were used as sources for historical bug data.
  • Target Libraries: Apple MLX, Huawei MindSpore, and OneFlow were used as newly introduced DL libraries for evaluation.
  • Fine-tuning Datasets: Over six hundred thousand entries were generated for fine-tuning LLMs, comprising code pairs for 128, 156, and 168 APIs across MLX, MindSpore, and OneFlow, respectively. These datasets were derived from API documentation, code examples, and historical bug codes.

Key Insights and Ideas

  • Leveraging Historical Bugs is Crucial: The paper strongly demonstrates that historical bug information from mature libraries is a rich source for finding bugs in new ones, a capability lacking in many existing fuzzers.
  • LLMs as Code Translators and Generators: Fine-tuning LLMs for specific tasks like code conversion and generation is highly effective for adapting fuzzing to new, less-documented libraries.
  • The "History to Future and Back" Cycle: The idea of using bugs found in new libraries to enhance older ones is a novel and powerful concept for continuous security improvement.
  • API Sequences Matter: FUTURE's ability to generate and test complex API sequences, rather than just individual calls, is key to uncovering deeper bugs.
  • Importance of NaNs and Infs: The research highlights that handling of numerical edge cases like NaNs and Infs is a common source of bugs in DL libraries.

Key Results

  • Bug Detection: FUTURE detected 148 bugs across 452 targeted APIs in MLX, MindSpore, and OneFlow.
  • Novelty of Bugs: Of these, 142 were previously unknown bugs.
  • CVEs: 10 bugs were assigned CVE IDs.
  • Reverse Security: FUTURE also detected 7 bugs in PyTorch, demonstrating its ability to enhance security in existing libraries.
  • Performance: FUTURE significantly outperformed baselines (TitanFuzz, NablaFuzz, TensorScope, Few-shot learning) in bug detection, bug reproduction success rate, code generation validity rate, and API coverage.
  • API Coverage: FUTURE achieved an average API coverage of 98.0% across target libraries, significantly higher than baselines.
  • Code Generation Validity: FUTURE's generated code snippets had a validity rate of 96.5%, substantially higher than TitanFuzz (263.7% of TitanFuzz's rate).

Limitations and Future Work

  • Manual Involvement: While largely automated, FUTURE requires manual effort for extracting bug-prone API inputs and inspecting some code pair generation failures.
  • LLM Variability: The effectiveness of LLM-generated code can vary, though FUTURE mitigates this through rigorous preprocessing and validity checks.
  • External Applicability: Applying FUTURE to DL libraries not initially targeted might require user familiarity with the fine-tuning process.
  • Future Work: The authors plan to expand the range of source libraries for historical bug information and implement more automated components to fully realize the "future back to history" cycle.

Summary updated

Abstract

The widespread application of large language models (LLMs) underscores the importance of deep learning (DL) technologies that rely on foundational DL libraries such as PyTorch and TensorFlow. Despite their robust features, these libraries face challenges with scalability and adaptation to rapid advancements in the LLM community. In response, tech giants like Apple and Huawei are developing their own DL libraries to enhance performance, increase scalability, and safeguard intellectual property. Ensuring the security of these libraries is crucial, with fuzzing being a vital solution. However, existing fuzzing frameworks struggle with target flexibility, effectively testing bug-prone API sequences, and leveraging the limited available information in new libraries. To address these limitations, we propose FUTURE, the first universal fuzzing framework tailored for newly introduced and prospective DL libraries. FUTURE leverages historical bug information from existing libraries and fine-tunes LLMs for specialized code generation. This strategy helps identify bugs in new libraries and uses insights from these libraries to enhance security in existing ones, creating a cycle from history to future and back. To evaluate FUTURE's effectiveness, we conduct comprehensive evaluations on three newly introduced DL libraries. Evaluation results demonstrate that FUTURE significantly outperforms existing fuzzers in bug detection, success rate of bug reproduction, validity rate of code generation, and API coverage. Notably, FUTURE has detected 148 bugs across 452 targeted APIs, including 142 previously unknown bugs. Among these, 10 have been assigned CVE IDs. Additionally, FUTURE detects 7 bugs in PyTorch, demonstrating its ability to enhance security in existing libraries in reverse.
BibTeX
@misc{li2024seeds,
  author = {Zhiyuan Li and Jingzheng Wu and Xiang Ling and Tianyue Luo and Zhiqing Rui and Yanjun Wu},
  title = {{The Seeds of the FUTURE Sprout from History: Fuzzing for Unveiling Vulnerabilities in Prospective Deep-Learning Libraries}},
  year = {2024},
  eprint = {2412.01317},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.01317},
}

Loading related content...

Figure