Abstract: Effective software vulnerability detection is paramount for ensuring the security of software systems. However, the presence of imbalanced data in extensive datasets often leads to overfitting on non-vulnerable code and suboptimal performance on vulnerable code. Traditional methods of collecting vulnerable data frequently fall short in capturing the complexities of real-world scenarios. This paper proposes a mutation-based data enhancement approach to tackle this challenge, with a focus on capturing essential traits of vulnerable source code. Our approach systematically extracts traits from extensive vulnerable source code and employs mutation operators to introduce high-level alterations. We evaluate the convergence of multiple mutation rounds using a diversity index to ensure consistent enhancements. By selecting the most effective mutation operators for subsequent model training, our approach achieves substantial accuracy improvements across diverse datasets and deep neural network models. This work represents the initial version of our approach, with continuous refinements underway to facilitate practical implementation and address real-world security challenges.
Introduction
Deep learning (DL) has become a cornerstone of automated software vulnerability detection. However, these models face a significant "data bottleneck." Real-world vulnerability datasets are inherently imbalanced; secure code is abundant, while documented vulnerabilities are relatively rare. When models are trained on such skewed data, they tend to overfit to the patterns of non-vulnerable code, resulting in poor performance when identifying actual security flaws.
While data augmentation is common in fields like computer vision, source code presents unique challenges. Unlike images, which can be flipped or cropped, code is highly structured. Randomly altering a code snippet can break its syntax or change its logic. This research introduces a mutation-based data enhancement strategy designed to generate valid, diverse, and semantically consistent vulnerable code samples to balance training sets.
Methodology
The proposed approach moves beyond simple oversampling (duplicating existing data) by applying "mutation operators" borrowed from software mutation testing. These operators make high-level, semantic-preserving alterations to the source code, ensuring the underlying vulnerability remains intact while the surrounding structure changes.
The pipeline consists of four primary phases:
- Formatting & Deduplication: Code is standardized by removing comments and normalizing spacing. Exact and near-duplicates are removed using the SimHash algorithm to ensure the model learns from unique patterns.
- High-Order Mutation: The system applies multiple rounds of random mutations to the source code.
- Diversity Filtering: To prevent the generation of near-identical clones, the text diversity of mutated samples is measured using the Self-BLEU index.
- Selection: After simulating up to 10 rounds of mutations, the system selects the mutation paths that yield the highest diversity scores for the final training set.
Mutation Strategy
The core innovation lies in the use of semantic-preserving transformations. For example, a for loop can be converted into a while loop without changing the program's logic or the nature of a memory leak contained within it. This forces the neural network to learn the generalized features of the vulnerability rather than memorizing specific syntactic structures.
Experimental Results
The approach was tested on two real-world datasets: Devign (C code from FFmpeg and QEMU) and REVEAL (Linux Debian and Chromium). We evaluated the augmented data across four recurrent neural network (RNN) architectures: RNN, BiRNN, LSTM, and BiLSTM.
- Performance Gains: On the Devign dataset, the BiLSTM model's F1 score increased from 0.569 to 0.641. Across all architectures, F1 scores improved by up to 21.73%.
- Generalization: On the highly imbalanced REVEAL dataset, the mutation approach increased the F1 score by 21.78% and recall by 24.86%, proving its effectiveness in severe class-imbalance scenarios.
- Failure of Simple Oversampling: A control group using simple data duplication showed almost no improvement (hovering around an F1 of 0.54), confirming that semantic diversity is the key driver of performance.
Conclusion and Future Work
This mutation-based approach demonstrates that syntax-aware data generation is far superior to simple oversampling for training vulnerability detection models. By maintaining a "Goldilocks zone" of dataset expansion (roughly 3x the original size), we can significantly improve model recall and F1 scores.
Future research will focus on expanding the mutation operator library to support other programming languages like Java and Python, and exploring methods to improve cross-project vulnerability detection, which remains a significant challenge in the field.
Summary updated