一句话:提出首个通用 Python 重量级动态分析框架 DynaPyt,提供分层钩子、选择性插桩与执行修改,并验证低开销。
Python 广泛用于机器学习、数据分析和 Web 等,安全与性能分析至关重要;但其动态特性使动态分析必要,现有工具却难以方便实现,开发者常需临时定制。本文提出 DynaPyt,首个面向 Python 的重量级通用动态分析框架,提供按层次组织的广泛分析钩子,并支持选择性插桩与执行修改,便于简洁实现分析。作者在 9 个开源 Python 项目(共 1,268,545 行)上评估,基本保持原语义;运行时间为原始执行的 1.2×–16×,比 Python 内置 tracing API 快 5.6%–88.6%。还实现了 PyTorch 显存爆炸检测、SQL 注入污点分析和性能反模式警告等分析。
Python is a widely used programming language that powers important application domains such as machine learning, data analysis, and web applications. For many programs in these domains it is consequential to analyze aspects like security and performance, and with Python’s dynamic nature, it is crucial to be able to dynamically analyze Python programs. However, existing tools and frameworks do not provide the means to implement dynamic analyses easily and practitioners resort to implementing an ad-hoc dynamic analysis for their own use case. This work presents DynaPyt, the first general-purpose framework for heavy-weight dynamic analysis of Python programs. Compared to existing tools for other programming languages, our framework provides a wider range of analysis hooks arranged in a hierarchical structure, which allows developers to concisely implement analyses. DynaPyt features selective instrumentation and execution modification as well. We evaluate our framework on test suites of 9 popular open-source Python projects, 1,268,545 lines of code in total, and show that it, by and large, preserves the semantics of the original execution. The running time of DynaPyt is between 1.2x and 16x times the original execution time, which is in line with similar frameworks designed for other languages, and 5.6%–88.6% faster than analyses using a built-in tracing API offered by Python. We also implement multiple analyses, show the simplicity of implementing them and some potential use cases of DynaPyt. Among the analyses implemented are: an analysis to detect a memory blow up in Pytorch programs, a taint analysis to detect SQL injections, and an analysis to warn about a runtime performance anti-pattern.
DOI 原文 ·
@inproceedings{paperbot7074,
title = {DynaPyt: a dynamic analysis framework for Python},
author = {Aryaz Eghbali and Michael Pradel},
booktitle = {FSE},
year = {2022},
doi = {10.1145/3540250.3549126}
}