Skip to main content
QUICK REVIEW

[Paper Review] Uncovering the Limits of Machine Learning for Automatic Vulnerability Detection

Niklas Risse, Marcel Böhme|arXiv (Cornell University)|Jun 28, 2023
Software Reliability and Analysis ResearchComputer Science3 citations
TL;DR

This paper proposes a benchmarking methodology to evaluate the robustness and generalization of machine learning models in automatic vulnerability detection. It introduces two algorithms: one that applies semantic-preserving transformations during training and testing to detect overfitting to specific transformations, and another that evaluates models on vulnerable code and their patches. The key finding is that models only generalize to the exact transformations used during training data amplification, indicating severe overfitting to label-unrelated features.

ABSTRACT

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.

Motivation & Objective

  • To address the lack of reliable evaluation methods for machine learning models in vulnerability detection.
  • To investigate whether improved robustness from data amplification is generalizable or specific to the transformations used.
  • To develop a benchmarking methodology that detects overfitting to label-unrelated features introduced by data augmentation.
  • To assess the ability of models to generalize to a modified detection setting, such as distinguishing vulnerabilities from their fixed versions.
  • To provide actionable tools for researchers to evaluate and improve model robustness in real-world deployment scenarios.

Proposed method

  • Proposes Algorithm 1: a cross-validation framework that applies different semantic-preserving transformations to training and testing sets to detect overfitting to specific transformations.
  • Applies 11 distinct semantic-preserving code transformations (e.g., identifier renaming, statement insertion, code element replacement) to both training and testing data.
  • Uses three state-of-the-art ML techniques (e.g., CodeBERT, GraphCodeBERT, and others) trained on amplified training data and evaluated on transformed test sets.
  • Introduces Algorithm 2: evaluates models on a testing set containing both vulnerable functions and their corresponding patches to measure out-of-distribution generalization.
  • Employs cross-entropy and accuracy metrics to quantify performance degradation across different transformation pairs and settings.
  • Validates the methodology on two widely used datasets: CodeXGLUE and VulDeePecker, despite their imbalanced class distributions.
(a) Test set accuracy over ten training epochs of different models trained with VulBERTa on the CodeXGLUE/Devign dataset. Amplifying the testing set $Te$ with transformation $t_{10}$ (green) decreases the accuracy, but applying the same transformation also to the training dataset $Tr$ (purple) resto
(a) Test set accuracy over ten training epochs of different models trained with VulBERTa on the CodeXGLUE/Devign dataset. Amplifying the testing set $Te$ with transformation $t_{10}$ (green) decreases the accuracy, but applying the same transformation also to the training dataset $Tr$ (purple) resto

Experimental results

Research questions

  • RQ1RQ1: Does training data amplification with specific semantic-preserving transformations improve model robustness beyond the transformations used during training?
  • RQ2RQ2: To what extent do models overfit to label-unrelated features introduced by data augmentation techniques?
  • RQ3RQ3: Can models trained on amplified data generalize to a modified detection setting that requires distinguishing between vulnerable code and their patches?
  • RQ4RQ4: How does the performance of models vary when the same transformation is applied to training and testing data versus different transformations?
  • RQ5RQ5: Can the proposed benchmarking methodology detect overfitting even when standard train-test performance gaps are minimal?

Key findings

  • When the same transformation is applied to both training and testing data, model accuracy is restored to 59.8% and 54.1% of original levels on CodeXGLUE and VulDeePecker, respectively.
  • When different transformations are applied to training and testing data, model accuracy drops by 35.7% and 97.4% on the two datasets, indicating severe overfitting to specific transformations.
  • Models trained with data amplification only generalize to the exact transformations used during training, failing to generalize to other semantic-preserving transformations.
  • The models are unable to distinguish between vulnerable code and their patches, showing poor out-of-distribution generalization as measured by Algorithm 2.
  • Even with standard regularization techniques (e.g., dropout, early stopping), models remain overfit to label-unrelated features introduced by data augmentation.
  • The proposed benchmarking methodology successfully detects overfitting that is undetectable in standard evaluation setups, where performance gaps between training and test sets are minimal.
(b) Extension of the results in Figure 2a , for all transformations $t_{k}\in T$ , and for all three ML techniques. The boxplots represent distributions of the resulting accuracies. Amplifying the testing set $Te$ with transformations $t_{k}\in T$ (green boxplots) decreases the accuracy, but applyin
(b) Extension of the results in Figure 2a , for all transformations $t_{k}\in T$ , and for all three ML techniques. The boxplots represent distributions of the resulting accuracies. Amplifying the testing set $Te$ with transformations $t_{k}\in T$ (green boxplots) decreases the accuracy, but applyin

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.