Introduction
Traditional automated vulnerability detection often relies on Code Pre-trained Models (CodePTMs) like CodeBERT. While effective on standard benchmarks, these models frequently act as "shortcut learners," overfitting to superficial features such as variable names or project-specific styles rather than understanding underlying logic. This leads to poor generalization on out-of-distribution (OOD) data and a lack of robustness against simple adversarial attacks, such as identifier renaming.
The VulLLM Framework
To address these limitations, the authors propose VulLLM, a framework that shifts vulnerability detection from pattern matching to reasoning. VulLLM leverages the capabilities of Large Language Models (LLMs) like Llama-2 and CodeLlama through a multi-task instruction fine-tuning approach.
Multi-Task Instruction Fine-Tuning
VulLLM is trained on three concurrent tasks to move beyond binary classification:
- Vulnerability Detection: Determining if code is buggy or secure.
- Vulnerability Localization: Identifying the specific lines responsible for the flaw.
- Vulnerability Interpretation: Generating natural language explanations of the root cause.
Patch-Enhanced CoT-SV
High-quality explanations are generated using GPT-4 via a Chain-of-Thought with Self-Verification (CoT-SV) process. This five-step pipeline involves role-playing, CVE description analysis, line identification, dependency analysis, and final synthesis to ensure accuracy and minimize hallucinations.
Data Augmentation
To decouple the model from naming conventions, Random Identifier Substitution is employed, replacing 10% of identifiers with random strings during training. This forces the model to prioritize structural logic over variable names.
Key Technical Insights
A core insight of this work is that teaching a model to explain a vulnerability serves as a powerful regularizer, improving its ability to detect them. By focusing on the structural context of a vulnerability—defined through Program Dependency Graphs (PDG)—the model learns the actual flow of data and control.
As shown in the PDG analysis, the model considers $k$-hop neighboring lines to capture the security-relevant context. This structural focus makes VulLLM significantly more robust than traditional models when faced with adversarial changes like dead code insertion or identifier renaming.
Experimental Results
VulLLM was evaluated across six C/C++ datasets, including DiverseVul, BigVul, and Juliet.
- Performance: VulLLM (CodeLlama-13B) achieved an F1 score of 66.54%, an 8% improvement over the UniXcoder baseline.
- Generalization: On OOD datasets, VulLLM's F1 score was 8.58% higher than baselines, indicating superior performance on unseen projects.
- Robustness: Under adversarial attacks, VulLLM maintained stability, outperforming UniXcoder by 68.08% in F1 score.
- Ablation: Removing multi-task learning led to a 9.3% performance drop, validating the importance of auxiliary tasks.
Conclusion and Future Work
VulLLM demonstrates that instruction fine-tuning for multi-task reasoning significantly enhances the generalization and robustness of vulnerability detection. While currently constrained by the computational costs of large models and the context window of 2048 tokens, future work will explore full fine-tuning and expanding context handling for larger codebases.
Summary updated