NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Generalization-Enhanced Code Vulnerability Detection via Multi-Task Instruction Fine-Tuning

Xiaohu Du, Ming Wen, Jiahao Zhu, Zifan Xie, Bin Ji, Huijun Liu, Xuanhua Shi, Hai Jin

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.

Overview of the VulLLM framework, illustrating the pipeline from feature extraction to multi-task instruction tuning.

Multi-Task Instruction Fine-Tuning

VulLLM is trained on three concurrent tasks to move beyond binary classification:

  1. Vulnerability Detection: Determining if code is buggy or secure.
  2. Vulnerability Localization: Identifying the specific lines responsible for the flaw.
  3. 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.

Visual representation of a Program Dependency Graph (PDG) highlighting the vulnerable line and its neighboring dataflow/controlflow nodes.

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

BibTeX
@inproceedings{du2024generalization,
  author = {Xiaohu Du and Ming Wen and Jiahao Zhu and Zifan Xie and Bin Ji and Huijun Liu and Xuanhua Shi and Hai Jin},
  title = {{Generalization-Enhanced Code Vulnerability Detection via Multi-Task Instruction Fine-Tuning}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.625},
}
Figure