Abstract: Large language models (LLMs) demonstrate considerable proficiency in numerous coding-related tasks; however, their capabilities in detecting software vulnerabilities remain limited. This limitation primarily stems from two factors: (1) the absence of reasoning data related to vulnerabilities, which hinders the models' ability to capture underlying vulnerability patterns; and (2) their focus on learning semantic representations rather than the reason behind them, thus failing to recognize semantically similar vulnerability samples. Furthermore, the development of LLMs specialized in vulnerability detection is challenging, particularly in environments characterized by the scarcity of high-quality datasets. In this paper, we propose a novel framework ReVD that excels at mining vulnerability patterns through reasoning data synthesizing and vulnerability-specific preference optimization. Specifically, we construct forward and backward reasoning processes for vulnerability and corresponding fixed code, ensuring the synthesis of high-quality reasoning data. Moreover, we design the triplet supervised fine-tuning followed by curriculum online preference optimization for enabling ReVD to better understand vulnerability patterns. The extensive experiments conducted on PrimeVul and SVEN datasets demonstrate that ReVD sets new state-of-the-art for LLM-based software vulnerability detection, e.g., 12.24%-22.77% improvement in the accuracy.
Introduction
While Large Language Models (LLMs) are increasingly proficient at writing code, they remain surprisingly limited in detecting security vulnerabilities. This performance gap is attributed to two primary hurdles: the Reasoning Gap and Semantic Overlap. Most training datasets lack the step-by-step logic (the "why") behind a fix, making it difficult for models to align code changes with abstract security patterns. Additionally, because vulnerability fixes are often subtle—sometimes just a single line—models often learn general code semantics rather than the specific patterns that make code dangerous.
The ReVD Framework
To bridge these gaps, we propose ReVD (Reasoning-centric Vulnerability Detection), a three-stage framework designed to enhance vulnerability detection through synthetic reasoning and specialized optimization.
The framework operates in three distinct phases:
- Bi-directional Vulnerability Data Generation (BVD): Using a teacher model, we generate synthetic reasoning data consisting of forward reasoning (deducing the cause of a vulnerability) and backward reasoning (explaining why a specific fix prevents it).
- Triplet Supervised Fine-Tuning (T-SFT): The model is trained on a triplet loss, analyzing vulnerable code (pre-code), fixed code (post-code), and the difference between them (code-diff). This forces the model to focus on the specific security-impacting changes.
- Curriculum Online Preference Optimization (COPO): The model undergoes iterative preference training using instance-level curricula (focusing on difficult vulnerability types) and task-level curricula (breaking detection into sub-tasks like location and root cause interpretation).
Key Insights: The Power of Reasoning
A striking finding of this research is that explicit reasoning traces are the "missing link" for LLM-based security analysis. By training on the "thought process" behind a fix, models can better distinguish between safe and unsafe code, even when the semantic difference is negligible.
As illustrated in Figure 1, ReVD identifies vulnerabilities arising from missing checks that general-purpose models like GPT-4 might overlook. The triplet loss ensures the model ignores the vast majority of unchanged code to focus entirely on the "subtle delta" that contains the security flaw.
Experimental Results
ReVD was evaluated on two major benchmarks: PrimeVul (a large-scale dataset with 140 CWE types) and SVEN (a manually vetted dataset of real-world C/C++ vulnerabilities).
- Accuracy Boost: On the PrimeVul dataset, ReVD improved accuracy by 12.24% to 22.77% over various baselines.
- Outperforming GPT-4: Integrated with the Qwen2.5-Coder-7B model, ReVD achieved an accuracy of 58.05% on PrimeVul, significantly higher than GPT-4’s 51.72%.
- VP-Score Improvement: ReVD showed a 23.64% improvement in the Vulnerability Pair-Score on SVEN, proving its ability to correctly distinguish between a bug and its fix.
Conclusion and Future Work
ReVD sets a new state-of-the-art for LLM-based software vulnerability detection by leveraging synthetic reasoning data and curriculum-based preference optimization. Future work will focus on scaling these methods to larger models and extending the context window to handle multi-file vulnerabilities in large-scale enterprise software.
Summary updated