TL;DR
This paper introduces a novel framework for using program refactoring as a data augmentation technique to improve deep learning models for vulnerability detection. While naive refactoring can hurt performance, a tuned approach significantly boosts model accuracy, especially on imbalanced datasets, by increasing code diversity.
What Problem Does This Paper Address?
The increasing prevalence of software vulnerabilities necessitates robust detection methods. Deep learning models have shown promise in this area, but their performance is hampered by limited and imbalanced datasets. Existing datasets often lack diversity and contain a disproportionate number of non-vulnerable code examples, leading to biased models that struggle to identify actual vulnerabilities. This paper aims to address these data-related challenges by leveraging program refactoring to create more diverse and balanced training data.
Methods
The core of this work is a framework for automatically applying "semantics-preserving" refactorings to C code. These refactorings alter the code's syntax without changing its underlying behavior. The authors implemented five specific refactorings adapted from prior work: RenameVariable, InsertNoop, PermuteStmt, SwitchExchange, and LoopExchange.
Their approach involves:
- Parsing: Using
srcMLto parse C code into an Abstract Syntax Tree (AST). - Refactoring: Applying selected refactorings based on predefined preconditions to ensure semantic preservation.
- Data Augmentation: Generating refactored versions of existing code samples and adding them to the training dataset.
- Tuning: Exploring different strategies for applying refactorings (e.g., applying them multiple times, targeting specific code changes) to optimize performance.
The key novelty lies in the systematic application and tuning of these refactorings as a data augmentation strategy specifically for vulnerability detection models.
Datasets
The study utilizes two established datasets for vulnerability detection:
- Devign: A dataset of approximately 22,361 functions, with labels manually validated by the authors, providing high confidence in its accuracy.
- ReVeal: A dataset of approximately 18,169 functions, labeled automatically based on code changes in commits. This dataset is noted to be imbalanced, with only about 9.16% of samples labeled as vulnerable, reflecting real-world scenarios.
Key Insights and Ideas
- Naive refactoring can be detrimental: Simply applying refactorings without careful consideration can actually decrease model performance. This is often due to introducing new tokens that are outside the model's vocabulary (e.g., random variable names), which deep learning models with fixed vocabularies struggle to handle.
- Tuning is crucial: The effectiveness of refactoring as data augmentation is highly dependent on the strategy used. Applying refactorings multiple times and targeting specific code changes (e.g., based on a threshold of modified lines) yields significantly better results than naive application.
- Refactoring for imbalance works: The refactoring framework shows promise in addressing data imbalance, particularly when targeting vulnerable programs. While not always outperforming specialized techniques like SMOTE, it offers a complementary approach.
- Broad applicability: The refactoring framework is designed to be applicable to a large majority of C programs, making it a practical tool for data augmentation.
Key Results
- Performance Improvement: A tuned refactoring configuration improved the F1 score of state-of-the-art vulnerability detection models by up to 3.49 points.
- Naive Refactoring Impact: In 3 out of 4 cases, naive refactoring (applying each refactoring once) degraded model performance, with F1 scores decreasing.
- NoNewNames Configuration: The
NoNewNamesconfiguration, which avoids introducing new variable names, showed improvements in recall for the Devign dataset and higher F1 scores compared to naive refactoring on the ReVeal dataset. - Thresholding: Increasing the refactoring threshold (percentage of lines changed) generally improved F1 scores, but optimal performance required tuning, as too much modification could lead to instability.
- Program Applicability: The study demonstrated that refactoring could be applied to a significant portion of programs, with up to 55% of lines changed in some cases.
Limitations and Future Work
- Reproducibility Issues: The authors encountered challenges reproducing the results of the ReVeal paper due to data leakage in their implementation, which artificially inflated performance. They fixed this leakage in their own implementation, leading to different results than the original paper.
- Hyperparameter Tuning: Finding the optimal refactoring configuration requires significant computational resources for grid search. Future work could explore more intelligent hyperparameter search methods (e.g., Bayesian optimization) to reduce this burden.
- Unsound Transformations: While this thesis focused on semantics-preserving refactorings, the authors suggest that exploring "unsound" transformations (like program mutation) could further increase program diversity and improve model performance, as demonstrated in other domains.
- Cross-Language Applicability: The refactoring framework uses
srcML, which supports languages beyond C (e.g., C++, Java). Future work could investigate the effectiveness of this refactoring approach for data augmentation in other programming languages. - Default Configuration: Developing a suitable default refactoring configuration that works well across a broad range of datasets and models would make the approach more practical.
Summary updated