[论文解读] Large Language Models are Zero-Shot Fuzzers: Fuzzing Deep-Learning Libraries via Large Language Models
TitanFuzz 是首个利用大型语言模型(LLMs)作为零样本模糊测试器,自动生成多样且有效的深度学习程序以测试 TensorFlow 和 PyTorch 库的框架。通过结合生成式 LLM(如 Codex)和补全式 LLM(如 InCoder)进行种子生成与进化变异,TitanFuzz 在 TensorFlow 和 PyTorch 上分别实现比最先进模糊测试器高 30.38% 和 50.84% 的代码覆盖率,并发现 65 个错误,其中 41 个为此前未知的错误。
Detecting bugs in Deep Learning (DL) libraries (e.g., TensorFlow/PyTorch) is critical for almost all downstream DL systems in ensuring effectiveness/safety for end users. Meanwhile, traditional fuzzing techniques can be hardly effective for such a challenging domain since the input DL programs need to satisfy both the input language (e.g., Python) syntax/semantics and the DL API input/shape constraints for tensor computations. To address these limitations, we propose TitanFuzz - the first approach to directly leveraging Large Language Models (LLMs) to generate input programs for fuzzing DL libraries. LLMs are titanic models trained on billions of code snippets and can auto-regressively generate human-like code snippets. Our key insight is that modern LLMs can also include numerous code snippets invoking DL library APIs in their training corpora, and thus can implicitly learn both language syntax/semantics and intricate DL API constraints for valid DL program generation. More specifically, we use both generative and infilling LLMs (e.g., Codex/InCoder) to generate and mutate valid/diverse input DL programs for fuzzing. Our experimental results demonstrate that TitanFuzz can achieve 30.38%/50.84% higher code coverage than state-of-the-art fuzzers on TensorFlow/PyTorch. Furthermore, TitanFuzz is able to detect 65 bugs, with 41 already confirmed as previously unknown bugs. This paper demonstrates that modern titanic LLMs can be leveraged to directly perform both generation-based and mutation-based fuzzing studied for decades, while being fully automated, generalizable, and applicable to domains challenging for traditional approaches (such as DL systems). We hope TitanFuzz can stimulate more work in this promising direction of LLMs for fuzzing.
研究动机与目标
- 为解决传统模糊测试在深度学习库中面临的限制,即输入程序必须满足复杂的语法、语义和张量形状约束。
- 克服以往 API 级别和模型级别模糊测试器在 API 序列多样性上的不足以及无法生成任意有效代码的问题。
- 探索现代大型语言模型(LLMs)是否可通过其在数十亿代码片段上的训练,直接作为深度学习库的零样本模糊测试器使用。
- 开发一个完全自动化、可泛化且高效的模糊测试框架,利用 LLM 生成和变异有效的深度学习程序。
提出的方法
- 使用生成式 LLM(如 Codex)并结合提示工程,生成在语法和语义上均正确且适用于深度学习库的高质量种子程序。
- 采用补全式 LLM(如 InCoder)通过在程序内插入、替换或删除代码片段,对种子程序执行进化变异。
- 应用差异测试判定器,通过比较 CPU 和 GPU 上的输出来检测不一致,从而识别潜在错误。
- 使用反馈驱动的进化算法,引导变异过程以提升代码覆盖率并增加错误检测率。
- 通过执行验证生成的程序,并监控崩溃、运行时错误或不同硬件后端之间的语义不一致。
实验结果
研究问题
- RQ1大型语言模型是否可在无需任务特定训练或种子数据库的情况下,有效用作深度学习库的零样本模糊测试器?
- RQ2与最先进的 API 级别和模型级别模糊测试器相比,基于 LLM 的生成与变异在提升代码覆盖率方面的有效性如何?
- RQ3基于 LLM 的模糊测试是否能发现传统模糊测试器遗漏的先前未知错误,尤其是在罕见或复杂的 API 序列中?
- RQ4LLM 在生成包含 Python 特有结构(如循环和控制流)的有效、多样化且复杂的深度学习程序方面的能力如何?
- RQ5提示工程和模型选择(如 Codex 与 InCoder)对生成测试程序的质量和多样性有何影响?
主要发现
- 与最先进模糊测试器相比,TitanFuzz 在 TensorFlow 上实现 30.38% 的更高代码覆盖率,在 PyTorch 上实现 50.84% 的更高覆盖率。
- 该框架在 PyTorch 和 TensorFlow 中共检测到 65 个独立错误,其中 53 个已确认,41 个为此前未知。
- 其中 10 个已确认错误直接由 LLM 生成的种子发现,无需任何变异,证明了初始程序生成质量极高。
- TitanFuzz 有效检测到 PyTorch 中一个仅在特定 API 序列(log 后接 matrix_exp)下触发的 GPU 专用同步错误,而此前工具未能发现。
- 该框架发现 TensorFlow 的 ParallelDynamicStitch API 中存在一个关键安全漏洞,源于静默的越界读取,由于该 API 使用率低且缺乏种子覆盖,此前模糊测试器未能发现。
- 其中一个检测到的不一致被开发人员拒绝为错误,原因是 CPU 和 GPU 上低层移位操作符存在差异,凸显了设计精确判定器的重要性。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。