[论文解读] Free Lunch for Testing: Fuzzing Deep-Learning Libraries from Open Source
FreeFuzz 是一种新颖的全自动方法,通过从开源源代码中挖掘代码——包括文档、开发者测试和真实世界模型——然后使用动态插桩提取运行时类型和形状信息,实现针对 API 级别的定向模糊测试。与 LEMON 相比,它实现了 1158 个被覆盖的 API(高出 9 倍),运行时开销降低 3.5 倍,并在 PyTorch 和 TensorFlow 中发现了 49 个错误,其中 38 个被开发者确认为此前未知的缺陷。
Deep learning (DL) systems can make our life much easier, and thus are gaining more and more attention from both academia and industry. Meanwhile, bugs in DL systems can be disastrous, and can even threaten human lives in safety-critical applications. To date, a huge body of research efforts have been dedicated to testing DL models. However, interestingly, there is still limited work for testing the underlying DL libraries, which are the foundation for building, optimizing, and running DL models. One potential reason is that test generation for the underlying DL libraries can be rather challenging since their public APIs are mainly exposed in Python, making it even hard to automatically determine the API input parameter types due to dynamic typing. In this paper, we propose FreeFuzz, the first approach to fuzzing DL libraries via mining from open source. More specifically, FreeFuzz obtains code/models from three different sources: 1) code snippets from the library documentation, 2) library developer tests, and 3) DL models in the wild. Then, FreeFuzz automatically runs all the collected code/models with instrumentation to trace the dynamic information for each covered API, including the types and values of each parameter during invocation, and shapes of input/output tensors. Lastly, FreeFuzz will leverage the traced dynamic information to perform fuzz testing for each covered API. The extensive study of FreeFuzz on PyTorch and TensorFlow, two of the most popular DL libraries, shows that FreeFuzz is able to automatically trace valid dynamic information for fuzzing 1158 popular APIs, 9X more than state-of-the-art LEMON with 3.5X lower overhead than LEMON. To date, FreeFuzz has detected 49 bugs for PyTorch and TensorFlow (with 38 already confirmed by developers as previously unknown).
研究动机与目标
- 为深度学习库自动化测试中的关键空白提供解决方案,这些库是深度学习模型开发的基础,但其测试程度远低于模型本身。
- 克服基于 Python 的深度学习库中动态类型带来的挑战,这些挑战阻碍了自动测试输入生成和类型推断。
- 通过利用真实世界代码和运行时插桩,实现高覆盖率、高效且自动化的深度学习库 API 模糊测试。
- 改进现有基于模型的测试方法(如 CRADLE、LEMON),这些方法存在代码覆盖率低、开销高和输入多样性有限的问题。
- 通过细粒度的、基于 API 的模糊测试,检测广泛使用的深度学习库(如 PyTorch 和 TensorFlow)中此前未知的缺陷。
提出的方法
- FreeFuzz 从三种开源源收集代码和模型:官方库文档、开发者测试套件以及公共代码仓库中的真实世界深度学习模型。
- 它对所有收集到的代码进行插桩并执行,以动态追踪 API 调用,捕获运行时的参数类型、取值以及输入/输出张量的形状。
- 利用追踪到的动态信息,为每个被覆盖的 API 生成目标化、类型感知的模糊测试输入,从而实现精确且高效的变异测试。
- 它在 API 级别采用基于覆盖率的模糊测试策略,专注于单元测试单个库函数,而非端到端的模型执行。
- 该方法使用轻量级运行时插桩,在最小化性能开销的同时最大化可观测的 API 行为。
- 它通过与现有测试断言器集成,比较模糊输入下的输出结果,识别出不一致情况,从而发现潜在缺陷。
实验结果
研究问题
- RQ1能否有效挖掘开源代码和模型,以自动生成多样且有效的深度学习库 API 测试输入?
- RQ2尽管存在动态类型,动态插桩是否能为基于 Python 的深度学习 API 可靠地提取类型和形状信息?
- RQ3与基于模型的测试相比,API 级模糊测试在代码覆盖率、效率和缺陷检测方面是否更具优势?
- RQ4FreeFuzz 与最先进的方法(如 LEMON)相比,在覆盖率、开销和真实世界缺陷发现方面表现如何?
- RQ5先前工作中的现有模型变异技术(如 LEMON)在多大程度上真正提升了覆盖率并检测到新缺陷?
主要发现
- FreeFuzz 为 PyTorch 和 TensorFlow 中的 1158 个热门 API 有效追踪了动态信息,相比 LEMON 覆盖的 128 个 API 实现了 900% 的提升。
- 该方法相比 LEMON 实现了 3.5 倍的更低运行时开销,证明了其在插桩和执行效率方面的优越性。
- FreeFuzz 在 PyTorch 和 TensorFlow 中发现了 49 个独立缺陷,其中 38 个被开发者确认为此前未知的问题。
- 研究发现,LEMON 的模型变异规则高度受限,无法显著提升代码覆盖率,限制了其有效性。
- 通过 FreeFuzz 实现的基于 API 的模糊测试,为发现底层库缺陷提供了一种比基于模型的差分测试更具可扩展性和有效性的替代方案。
- 利用来自文档和开源模型的真实世界代码,相比基于合成或预训练模型的方法,能够实现更广泛且更真实的 API 覆盖。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。