[论文解读] Uncovering the Limits of Machine Learning for Automatic Vulnerability Detection
本文提出了一种基准测试方法,用于评估机器学习模型在自动漏洞检测中的鲁棒性和泛化能力。该方法引入了两种算法:一种在训练和测试过程中应用语义保持变换,以检测对特定变换的过拟合;另一种则在包含漏洞代码及其补丁的测试集上评估模型,以衡量分布外泛化能力。主要发现表明,模型仅能泛化到训练数据增强期间使用的精确变换,表明其对与标签无关的特征存在严重过拟合。
Recent results of machine learning for automatic vulnerability detection (ML4VD) have been very promising. Given only the source code of a function $f$, ML4VD techniques can decide if $f$ contains a security flaw with up to 70% accuracy. However, as evident in our own experiments, the same top-performing models are unable to distinguish between functions that contain a vulnerability and functions where the vulnerability is patched. So, how can we explain this contradiction and how can we improve the way we evaluate ML4VD techniques to get a better picture of their actual capabilities? In this paper, we identify overfitting to unrelated features and out-of-distribution generalization as two problems, which are not captured by the traditional approach of evaluating ML4VD techniques. As a remedy, we propose a novel benchmarking methodology to help researchers better evaluate the true capabilities and limits of ML4VD techniques. Specifically, we propose (i) to augment the training and validation dataset according to our cross-validation algorithm, where a semantic preserving transformation is applied during the augmentation of either the training set or the testing set, and (ii) to augment the testing set with code snippets where the vulnerabilities are patched. Using six ML4VD techniques and two datasets, we find (a) that state-of-the-art models severely overfit to unrelated features for predicting the vulnerabilities in the testing data, (b) that the performance gained by data augmentation does not generalize beyond the specific augmentations applied during training, and (c) that state-of-the-art ML4VD techniques are unable to distinguish vulnerable functions from their patches.
研究动机与目标
- 为解决机器学习模型在漏洞检测中缺乏可靠评估方法的问题。
- 探究通过数据增强提升的鲁棒性是否具有泛化性,还是仅限于所使用的变换类型。
- 开发一种基准测试方法,以检测由数据增强引入的与标签无关特征的过拟合现象。
- 评估模型在修改后的检测设置下的泛化能力,例如区分漏洞代码与其修复版本的能力。
- 为研究人员提供可操作的工具,以评估并提升模型在真实部署场景中的鲁棒性。
提出的方法
- 提出算法1:一种交叉验证框架,对训练集和测试集分别应用不同的语义保持变换,以检测对特定变换的过拟合。
- 对训练集和测试集均应用11种不同的语义保持代码变换(例如:标识符重命名、语句插入、代码元素替换)。
- 使用三种最先进的机器学习技术(例如:CodeBERT、GraphCodeBERT及其他)在增强后的训练数据上进行训练,并在变换后的测试集上进行评估。
- 引入算法2:在包含漏洞函数及其对应补丁的测试集中评估模型,以衡量分布外泛化能力。
- 采用交叉熵和准确率指标,量化不同变换对与设置下的性能下降程度。
- 在两个广泛使用的数据集(CodeXGLUE 和 VulDeePecker)上验证该方法,尽管其类别分布存在不平衡。

实验结果
研究问题
- RQ1RQ1:使用特定语义保持变换进行训练数据增强后,模型的鲁棒性是否超越了训练期间所用的变换?
- RQ2RQ2:模型在多大程度上对数据增强技术引入的与标签无关的特征产生过拟合?
- RQ3RQ3:在增强数据上训练的模型能否泛化到需要区分漏洞代码与其补丁的修改后检测设置?
- RQ4RQ4:当相同变换应用于训练和测试数据时,与使用不同变换相比,模型性能如何变化?
- RQ5RQ5:即使标准训练-测试性能差距较小,所提出的基准测试方法是否仍能检测到过拟合?
主要发现
- 当在训练和测试数据上应用相同变换时,模型在CodeXGLUE和VulDeePecker数据集上的准确率分别恢复至原始水平的59.8%和54.1%。
- 当在训练和测试数据上应用不同变换时,模型在两个数据集上的准确率分别下降35.7%和97.4%,表明对特定变换存在严重过拟合。
- 通过数据增强训练的模型仅能泛化到训练期间使用的精确变换,无法泛化到其他语义保持变换。
- 模型无法区分漏洞代码与其补丁,表明其在算法2测量下的分布外泛化能力较差。
- 即使使用标准正则化技术(如dropout、早停),模型仍对数据增强引入的与标签无关特征产生过拟合。
- 所提出的基准测试方法成功检测到在标准评估设置中难以察觉的过拟合现象,此时训练集与测试集的性能差距极小。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。