Abstract
Software Vulnerability Detection (SVD) is a critical task often hampered by the scarcity of labeled data and significant domain shifts between different software projects. We present DAM2P, an end-to-end framework that leverages adversarial domain adaptation to align feature distributions across projects and a novel max-margin kernel classifier to address extreme class imbalance. Experimental results on several open-source C/C++ projects demonstrate that DAM2P significantly outperforms existing state-of-the-art methods in cross-project vulnerability detection.
Introduction
Detecting software vulnerabilities is akin to finding a "needle in a haystack." The task is complicated by two primary factors: data scarcity and domain shift. Manually labeling vulnerabilities is an expert-intensive process, resulting in a severe lack of labeled data. Furthermore, a model trained on one project (e.g., a media player) often fails on another (e.g., an image library) because coding patterns vary significantly. Most existing models are also overwhelmed by the "non-vulnerable" majority class, failing to identify rare security flaws effectively.
The DAM2P Framework
The proposed DAM2P (Domain Adaptation with Max-Margin Principle) framework addresses these challenges through three integrated components:
- Automatic Feature Extraction: Utilizing a Bidirectional Recurrent Neural Network (Bi-RNN) with LSTM cells, the model captures the sequential context of code statements, transforming raw code into dense vectorial representations.
- Adversarial Domain Adaptation: To bridge the gap between different codebases, DAM2P employs a GAN-like adversarial training process. A generator creates features that a discriminator cannot distinguish as belonging to either the source or target project, effectively aligning them in a joint latent space.
- The Max-Margin Principle: This core innovation replaces standard classifiers with a cross-domain kernel classifier. It learns a hyperplane that maximizes the distance between rare "vulnerable" samples and the "non-vulnerable" majority, specifically tailored for imbalanced security data.
Experimental Evaluation
The researchers evaluated DAM2P using five prominent open-source C/C++ projects: FFmpeg, VLC, and Pidgin as source domains, and LibPNG and LibTIFF as target domains. The experiments focused on "Cross-Project" tasks where the model is trained on one project and tested on another. The dataset comprised 379 vulnerable functions and over 25,000 non-vulnerable functions, reflecting realistic class imbalances.
Key Results
DAM2P consistently outperformed state-of-the-art baselines, including specialized SVD models like VulDeePecker and general domain adaptation methods like SCDAN.
The F1-measure, a critical metric for imbalanced classification, saw improvements ranging from 1.83% to 6.25% over the next best methods. Notably, the model maintained high precision and recall even when no labels were available for the target project during training.
Insights and Discussion
- Ineffectiveness of Oversampling: The authors observed that standard oversampling techniques like SMOTE actually degraded performance. They suggest that oversampling may "blur" the latent space, hindering effective domain alignment.
- Domain of Majority: By leveraging the max-margin principle, the model defines a geometric "domain of majority" for non-vulnerable code, allowing it to treat vulnerabilities as distinct outliers.
- Latent Space Alignment: t-SNE visualizations confirmed that DAM2P successfully intermingles source and target code clusters, which remain isolated in baseline models.
Conclusion and Future Work
DAM2P represents a significant advancement in cross-project vulnerability detection. However, limitations remain. The current model operates at the function level, identifying buggy functions but not specific lines of code. Future work will aim to increase granularity to the statement level and explore applications in automated vulnerability patching. Additionally, while the architecture is general, further research is needed to adapt tokenization strategies for languages beyond C/C++.
Summary updated